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

相关推荐
hunterandroid5 小时前
内存泄漏与 LeakCanary:从问题定位到修复思路
前端
默_笙5 小时前
⭐ 从写 Prompt 到搭上下文:AI 终于不再对我"正确的胡说八道"了
javascript
用户94688315057505 小时前
四、elpis 基于 vue3 完成动态组件库建设
前端
用户298698530145 小时前
如何在 JavaScript 和 React 中下载/导出 Excel 文件
前端·javascript·react.js
你怎么知道我是队长5 小时前
JavaScript的介绍
开发语言·javascript·ecmascript
anyup5 小时前
uView Pro 正式支持 MCP 协议!让 AI 秒懂你的组件库
前端·uni-app·ai编程
触底反弹5 小时前
🔥 50 行代码,我手写了一个 MCP Server 给 Claude 用!
javascript·人工智能·程序员
要开心吖ZSH5 小时前
处方物流信息同步优化:从 36 秒到亚秒级的踩坑记录
java·数据库·mysql·性能优化
Coffeeee5 小时前
从 Android 15 到 Android 17,谷歌猝不及防的音频改动
android·前端·google
Wang's Blog5 小时前
JavaWeb快速入门: MyBatis入门与实战
java·mybatis