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

相关推荐
GISer_Jing2 分钟前
GeoFlow-AI:智能三维地理空间处理平台
前端·人工智能·架构
WordPress学习笔记2 分钟前
建外贸独立站公司
前端·wordpress
eSsO KERF3 分钟前
MS SQL Server partition by 函数实战三 成绩排名
java
OtIo TALL5 分钟前
Redis 6.2.7安装配置
前端·数据库·redis
ZC跨境爬虫6 分钟前
对称加密算法详解(DES篇):特点、实现与逆向实操
前端·javascript·爬虫
Hello--_--World11 分钟前
VUE3:基础篇官网笔记
前端·vue.js·笔记
我是伪码农16 分钟前
vue复习
前端·javascript·vue.js
姗姗的鱼尾喵21 分钟前
Java 并发编程高频面试题(含AQS/线程池/锁)
java·经验分享·面试
我是伪码农24 分钟前
JS考核复写
前端·javascript·css
JianZhen✓27 分钟前
前端开发AI工具全攻略:Cursor省Token+模型选择+免VPN工具+万能提示词
前端·人工智能