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

相关推荐
hashiqimiya6 分钟前
两个步骤,打包war,tomcat使用war包
java·服务器·前端
大筒木老辈子18 分钟前
C++笔记---并发支持库(atomic)
java·c++·笔记
Cricyta Sevina18 分钟前
Java Collection 集合进阶知识笔记
java·笔记·python·collection集合
小a杰.21 分钟前
Flutter 设计系统构建指南
开发语言·javascript·ecmascript
BD_Marathon27 分钟前
【JavaWeb】Servlet_url-pattern的一些特殊写法问题
java·开发语言·servlet
黄俊懿29 分钟前
【深入理解SpringCloud微服务】Seata(AT模式)源码解析——开启全局事务
java·数据库·spring·spring cloud·微服务·架构·架构师
零度@39 分钟前
Java中Map的多种用法
java·前端·python
中文很快乐40 分钟前
java开发--开发工具全面介绍--新手养成记
java·开发语言·java开发·开发工具介绍·idea开发工具
yaoxin5211231 小时前
268. Java Stream API 入门指南
java·开发语言·python
ss2731 小时前
ConcurrentLinkedQueue实战:电商秒杀系统的队列选型优化
java·开发语言·安全