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

相关推荐
10WTW0122 分钟前
Sprite-Motion-Lab:雪碧图动画编辑器
前端·css·雪碧图·spritemotionlab·10wtw01
夏天要喝冰可乐37 分钟前
用 Gitee Go 搭建WorkBuddy云端定时任务
前端·ai编程
天天鸭1 小时前
5 万处中文的老项目实现国际化,如何用架构思维完成改造?
前端·javascript·架构
程序员黑豆1 小时前
鸿蒙应用开发之持久化存储解析:PersistentStorage / PersistenceV2 / preferences 选型与实战
前端·harmonyos
明月_清风1 小时前
🚀 OpenAI 数据代理架构全解析:从 600 PB 到自然语言的六层上下文工程
前端·后端·架构
明月_清风1 小时前
🚀 从 Foundry 到 AIP:Palantir 发生了什么变化?一篇文章全搞懂
前端·后端
西门啐血1 小时前
Vue 缓存之坑,变量赋值方式和响应式数据
前端·vue.js·缓存
涛涛ing2 小时前
2026 上半年,前端圈已经炸了五次
前端
hunterandroid2 小时前
Android 后台任务可靠性排查:从 WorkManager 观测到失败重试闭环
android·前端
skiyee2 小时前
🔥 oiyo & unibest = 又新又好的 uniapp 模板
前端·uni-app