当前位置: 首页 > news >正文

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

http://www.lryc.cn/news/492573.html

相关文章:

  • 逻辑处理器核心指纹修改
  • 如何制作项目网页
  • mongodb/redis/neo4j 如何自己打造一个 web 数据库可视化客户端?
  • 1、正则表达式
  • Airsim安装问题:This project was made with a different version of the Unreal Engine.
  • java八股-分布式服务的接口幂等性如何设计?
  • vscode python code runner执行乱码
  • Java中的继承详解
  • kafka进阶_2.存储消息
  • 如何启用本机GPU硬件加速猿大师播放器网页同时播放多路RTSP H.265 1080P高清摄像头RTSP视频流?
  • 如何更好地设计SaaS系统架构
  • 表征对齐在训练DiT模型中的重要性
  • Qt中CMakeLists.txt解释大全
  • 【在 PyTorch 中使用 tqdm 显示训练进度条,并解决常见错误TypeError: ‘module‘ object is not callable】
  • 数据结构-堆的实现和应用
  • 数据分析的尽头是web APP?
  • YOLO系列论文综述(从YOLOv1到YOLOv11)【第3篇:YOLOv1——YOLO的开山之作】
  • 容器和它的隔离机制
  • 【数据结构与算法】排序算法总结:冒泡 / 快排 / 直接插入 / 希尔 / 简单选择 / 堆排序 / 归并排序
  • Windows Serv 2019 虚拟机 安装Oracle19c,图文详情(超详细)
  • 数字孪生开发之 Three.js 插件资源库(2)
  • 小米C++ 面试题及参考答案下(120道面试题覆盖各种类型八股文)
  • OpenOCD之J-Link下载
  • 华为云云连接+squid进行正向代理上网冲浪
  • 情绪识别项目
  • 【RISC-V CPU debug 专栏 2.2 -- Hart DM States】
  • 从零样本到少样本学习:一文读懂 Zero-shot、One-shot 和 Few-shot 的核心原理与应用!
  • 【LC】3101. 交替子数组计数
  • 如何构建SAAS项目
  • 树莓派搭建NextCloud:给数据一个安全的家