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

Vue3 父子组件数据传递

1、父组件向子组件传递数据

1.1、传递多个简单变量给到子组件

父组件使用

  <TitleView title="标题" :name="name" :isCollect="isCollect" @collect-event="collectEvent" /><script setup>const name = ref('名字')const isCollect = ref(true)</script>

子组件接收并且向外暴露一个方法

<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'const props = defineProps<{ title: string; name: string; isCollect: boolean }>()
const emits = defineEmits(['collectEvent'])
const isCollectRef = ref(props.isCollect)function doCollect() {isCollectRef.value = !isCollectRef.valueemits('collectEvent', isCollectRef.value)
}
</script>

1.2、传递对象给到子组件

父组件传递

<IndicatorDetail :detail="detailIndex"/>
<script setup>
const detailIndex = reactive([{text:'未知',title:'X',color:'green'
},{text:'未知',title:'Y',color:'blue'
},{text:'2023-08-13',title:'Z',color:'grey'
}])
</script>

子组件直接通过props接收

<script>
export default {props: ['detail'],setup(props) {}
}
</script>
或者
<script setup>
const props = defineProps({detail: {type: Object,default: () => {return {}}}
})
</script>
http://www.lryc.cn/news/133145.html

相关文章:

  • Eureka:集群环境配置
  • springboot之多数据源配置
  • 无涯教程-PHP - 静态变量函数
  • 2023-08-20力扣今日二题
  • 【地理专题】2023年最新全国A级景区数
  • Elasticsearch实战(一):Springboot实现Elasticsearch统一检索功能
  • 更改计算机睡眠时间
  • Matplotlib数据可视化(一)
  • LLM提示词工程和提示词工程师Prompting and prompt engineering
  • Python开发环境(Visual Studio Code、Anaconda、PyInstaller、Enigma Virtual Box)
  • Unreal Engine 测试总结
  • Air780EG —— 合宙4G定位解决方案
  • 【算法刷题之数组篇(2)】
  • chromedriver.exe 的所有版本下载地址
  • C++ 网络编程项目fastDFS分布式文件系统(四)-fastCGI项目相关技术以及linux搜狗输入法相关问题。
  • 【HarmonyOS】服务卡片 API6 JSUI跳转不同页面
  • 【linux】debian10安装vim
  • 文件同步工具rsync
  • 【嵌入式开发 Linux 常用命令系列 12 -- linux 下 log 输出重定向 详细介绍 】
  • gin中关于参数注入问题
  • 记录首次面试2023-08-18
  • 【Apollo学习笔记】——规划模块TASK之LANE_CHANGE_DECIDER
  • rabbitmq的死信队列
  • 利用网络对拷工具进行系统安装与恢复
  • opencv-python使用鼠标点击图片显示该点坐标和像素值IPM逆透视变换车道线二值化处理
  • AIGC绘画:kaggle部署stable diffusion项目绘画
  • 微服务概述-7
  • 十二、Linux如何修改文件/文件夹所属用户or用户组?chown命令
  • 企业百家号蓝V认证后,百度营销基木鱼落地页如何嵌入百家号中
  • Redis缓存读写策略(三种)数据结构(5+3)