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 一样

相关推荐
asdfg12589637 分钟前
Java中的Comparator 和JS中的回调函数好相似
java·开发语言
会编程的土豆13 分钟前
消息队列(MQ)入门笔记
java·笔记·spring
万少19 分钟前
万少的 Claude Code 入门教程
前端·人工智能·后端
专注VB编程开发20年19 分钟前
python运行提速方案全解
java·linux·服务器
涤生大数据23 分钟前
大数据面试高频题:row_number() 数据倾斜到底怎么解决?
java·大数据·面试
weixin_4467291623 分钟前
注解和反射
java·开发语言
摇滚侠28 分钟前
HashMap 源码解析 底层原理 面试如何回答
java·面试·职场和发展
এ慕ོ冬℘゜29 分钟前
JS 前端基础高频面试题
开发语言·前端·javascript
凯瑟琳.奥古斯特31 分钟前
常见加密算法及应用
java·开发语言·网络·网络协议·职场和发展
放下华子我只抽RuiKe532 分钟前
React 从入门到生产(八):测试与部署
前端·javascript·深度学习·react.js·前端框架·ecmascript·集成学习