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

相关推荐
jinyishu_17 小时前
模拟实现 C++ 栈和队列——从适配器模式看懂 STL 容器之美
java·c++·适配器模式
前端工作日常17 小时前
我学习到的Java类和对象区别
java·后端
前端工作日常18 小时前
我学习到的Java类完整结构
java·后端
触底反弹18 小时前
🔥 从零搭建 RAG 知识库:爬虫→分词→向量化→检索,一步都不能错
javascript·人工智能·面试
什巳18 小时前
JAVA练习309- 二叉树的层序遍历
java·数据结构·算法·leetcode
宠友信息18 小时前
消息序号如何保证即时通讯源码聊天记录稳定加载
java·spring boot·redis·python·mysql·uni-app
圣光SG18 小时前
Java Web入门基础知识笔记
java·前端·笔记
行思理19 小时前
微信支付“商家转账用户确认模式”,新手教程
java·开发语言·微信
cyforkk19 小时前
Vercel 绑定自定义域名极简配置指南
服务器·前端·网络
空中湖20 小时前
Spring AI RAG 完整实战:从零搭建企业知识库问答系统
java·人工智能·spring