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

相关推荐
噢,我明白了9 分钟前
表单的完整 CRUD 练习【极简个人记账本】(含前端后端链接mySQL)
java·前端·数据库·mysql
幽络源小助理13 分钟前
MacCMSPro版视频影视系统源码_全开源高可用视频平台解决方案
前端·php·php源码
通往曙光的路上15 分钟前
mysql1
java
Tigshop开源商城5 小时前
『物流设置+SEO优化』Tigshop开源商城系统 JAVA v5.8.26 版本更新!
java·开源商城系统·tigshop
Tigshop开源商城7 小时前
『订单税率+收货地址校验国家字段』功能上新|跨境运营更高效,Tigshop开源商城系统 JAVA v5.8.23 版本更新
java·开源商城系统·tigshop
不会敲代码17 小时前
手写 Zustand:三十分钟带你搞懂状态管理库的核心原理
前端·javascript·源码
神奇的程序员7 小时前
重构了自己5年前写的截图插件
前端·javascript·架构
REDcker7 小时前
C++变量存储与ELF段布局详解 从const全局到rodata与nm_readelf验证实践
java·c++·面试
橙淮7 小时前
从优化到安全再到未来 ——JavaScript 全维度技术指南
javascript
UXbot8 小时前
一人独立交付 UI + 前端:AI 驱动 UI 设计工具的五大功能模块深度评测
前端·低代码·ui·设计模式·交互