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

相关推荐
卿雪6 分钟前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
接着奏乐接着舞11 分钟前
react useMeno useCallback
前端·javascript·react.js
lkbhua莱克瓦2412 分钟前
IO流练习(修改文件中的数据)
java·windows·学习方法·io流·java练习题·io流练习
码农阿豪15 分钟前
Vue项目构建中ESLint的“换行符战争”:从报错到优雅解决
前端·javascript·vue.js
老华带你飞17 分钟前
汽车销售|汽车报价|基于Java汽车销售系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端·汽车
西岭千秋雪_28 分钟前
MySQL集群搭建
java·数据库·分布式·mysql
小马爱打代码32 分钟前
Spring AI:文生视频 - wanx2.1-i2v-plus
java·人工智能·spring
华仔啊39 分钟前
RebbitMQ 入门教程看这一篇就够了
java·后端·rabbitmq
象象翔41 分钟前
AI+若依(实战篇)
java·人工智能·spring boot·spring
CHANG_THE_WORLD1 小时前
C++ vs Python 参数传递方式对比
java·c++·python