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

相关推荐
问心无愧0513几秒前
ctf show web入门101
android·前端·笔记
MrJson-架构师1 分钟前
AgentScope Java 2.0:打造分布式、企业级智能体底座
java·开发语言·分布式
AI周红伟13 分钟前
事件分析:FDE标准,“OpenClaw+RAG+Agent” 应用实战的标准
前端·人工智能·chrome·chatgpt·aigc
Mike_jia21 分钟前
Databasus:开源数据库备份革命的里程碑,企业级数据安全的守护神
前端
fengxin_rou21 分钟前
深入理解Java类加载机制:从原理到实战详解
java·开发语言
糖果店的幽灵22 分钟前
Spring AI 从入门到精通-Prompt 工程
java·spring·prompt
小江的记录本25 分钟前
【Spring全家桶】Spring Cloud 2023.0.x:配置中心:Nacos Config、Apollo(附《思维导图》+《面试高频考点清单》)
java·spring boot·后端·python·spring·spring cloud·面试
恋猫de小郭25 分钟前
真正的跨平台 AI 自动化框架,甚至还支持鸿蒙
android·前端·flutter
IT_陈寒26 分钟前
Redis的LRU淘汰策略坑了我一天血汗
前端·人工智能·后端
weixin_4083180426 分钟前
2026年医疗直播行业趋势报告:技术方向、监管变化与市场格局
java·大数据·人工智能