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

相关推荐
用户255778850812 分钟前
axios请求缓存
前端
夫瑞3 分钟前
TypeScript 直接编译成原生二进制,没有浏览器,没有 V8
前端
spencer_tseng4 分钟前
java.lang.ClassNotFoundException: org.slf4j.Logger
java·spring·maven
Talents4 分钟前
OpenLayers 7.5.2 判断点是否在区域边上
前端
共享家95275 分钟前
单例模式( 饿汉式与懒汉式 )
开发语言·javascript·ecmascript
cmd7 分钟前
前端基础必看:JS 变量提升 & 函数提升完整解析
前端·javascript
小金鱼Y7 分钟前
前端必看:this 不是玄学!5 大绑定规则帮你永久告别 this 困惑
前端·javascript·面试
谁在黄金彼岸8 分钟前
用 AI 设计力打造专业 UI/UX:在 Trea、Qoder 等 AI IDE 中集成 ui-ux-pro-max-skill
前端
小江的记录本12 分钟前
【VO、DTO、Entity】VO、DTO、Entity三大核心数据对象全解析(附核心对比表 + 代码示例)
java·数据库·spring boot·spring·架构·mybatis·数据库架构