vue3 多种方式接受props,定义ref,reactive

定义props

1 第一种

interface AddType {

dialogStudyVisible: boolean;

}

const props = defineProps<AddType>();

第二种

// const props = defineProps({

// dialogStudyVisible:{

// type:Boolean,

// default:false

// }

// })

第三种

// const props = withDefaults(

// defineProps<{

//finishHandle: () => void //可以接受父节点方法

// dialogStudyVisible?:boolean

updatedHandle: (data:any) => void;

// }>(),

// {

// dialogStudyVisible:false,

//finishHandle: () => {}

updateHandle: () => {}

// }

// )

//自己业务逻辑

if(1=== 1){

props.finishHandle();

props.updateHandle(val);

}

定义ref

import { CAStep } from "../types";

export enum CAStep { plan = 1, plan = 2, }

1定义枚举类型

const step = ref<CAStep>(CAStep.plan);

2 -1定义对象类型

const columns = ref<StudyPreviewList>(\[\]);

import { StudyPreviewList } from "@/api/interface/studyPath/index";

export interface StudyPreview{

headInfo1:{

propertyId:string,

propertyValue:string

},

stage0:{

propertyId:string,

propertyValue:string

}

}

export interface StudyPreviewList {

StudyPreviewList: StudyPreview\[\];

}

2-2 定义对象类型

const pList = ref<{

id: string;

name: string;

owner: number;

}\[\]>(\[\]);

const planForm = reactive<{

planId: string;

address: boolean;

list: string\[\];

}>({

planId: '',

address: false,

list: \[\],

});

reactive 和 ref 一样

相关推荐
DevChronosands_3 分钟前
浅谈感受之 React 与 Vue 😒
前端
T_Apollo4 分钟前
3.1 JVM 工作原理
java
代码猎人4 分钟前
前端怎么掌握模块化
前端
天才熊猫君5 分钟前
前端队列,我是怎么从 `push + shift` 换成游标的
前端·javascript
Qinging6 分钟前
var_let_const
javascript
Java内核笔记8 分钟前
同一份知识库,4 种切分 × 3 种召回,纯关键词比纯向量高 13 个点
java·人工智能·spring boot
星_离11 分钟前
《Ajax - 实战基础篇》
前端·ajax
海岳云舟17 分钟前
springboot单元测试技术
java·后端·spring
Maxkim17 分钟前
私钥就是数字 4:扒一扒这场把一家 CA 直接送走的事故
javascript·架构
gCode Teacher 格码致知19 分钟前
前端教学8:提高 CSS 选择器的优先级,有哪些方法?
前端·css·html5