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

相关推荐
芭拉拉小魔仙6 小时前
企业级Vue项目的状态管理:从原理到实战架构
前端·vue.js·架构
恋猫de小郭6 小时前
丰田正在使用 Flutter 开发游戏引擎 Fluorite
android·前端·flutter
Frostnova丶6 小时前
LeetCode 190.颠倒二进制位
java·算法·leetcode
闻哥6 小时前
Redis事务详解
java·数据库·spring boot·redis·缓存·面试
hrhcode6 小时前
【Netty】五.ByteBuf内存管理深度剖析
java·后端·spring·springboot·netty
扶苏10026 小时前
Vue 3 响应式原理深度解析
前端·javascript·vue.js
NEXT066 小时前
React 性能优化:图片懒加载
前端·react.js·面试
PineappleCoder7 小时前
别让字体拖了后腿:FOIT/FOUT 深度解析与字体加载优化全攻略
前端·性能优化
道亦无名7 小时前
aiPbMgrSendAck
java·网络·数据库
发现你走远了7 小时前
Windows 下手动安装java JDK 21 并配置环境变量(详细记录)
java·开发语言·windows