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

相关推荐
SL_staff3 分钟前
制造订单交付闭环实践:用跨部门计划模板解决缺料-停机-返工三角死循环
java·开源·产品
device_Any7 分钟前
接口文档写着三个字段,接口返回了五个
android·java·linux
Wang's Blog12 分钟前
Java 项目实战: 交友项目 - 小视频模块实战:访客记录、FastDFS 存储与 SpringCache 缓存
java·缓存·交友
香蕉大香蕉(06敬畏市场)23 分钟前
MySQL 单点详解(09)
java·数据库·mysql·面试·八股·大厂实习
January120741 分钟前
【AI方法笔记】2026-11-02:模型流式吐 JSON 时,前端会遇到四种崩法
前端·人工智能·笔记·json
asdzx6744 分钟前
C# 操作 PDF 元数据:从属性写入到字段提取的完整流程
前端·pdf·c#
幻境如梦丶皆为虚1 小时前
从零写一个 DSH 插件:在左侧菜单栏加一个「测试」
开发语言·javascript·ecmascript
吹什么轩1 小时前
constexpr 完全指南:从 const 的两种含义,到编译期计算的四次演进
java·前端·javascript
她的男孩1 小时前
租户 A 的验证码,却用了租户 B 的 AccessKey:Forge Admin 修跨租户短信串发
java·spring boot·saas
LabVIEW开发1 小时前
LabVIEW 局部变量与数据流:这道 CLAD 题为什么答案是 Undefined
java·开发语言·labview