当前位置:网站首页>数据总线bus实现兄弟组件之间的通信
数据总线bus实现兄弟组件之间的通信
2022-04-22 05:46:00 【Python User】
定义一个数据总线bus.js,Abro组件给Bbro组件传值
bus.js
import Vue from 'vue'
const busData = new Vue();
export default busData
Abro.vue
import busData from './bus'
export default {
data(){
return {
title:'this is title!' } }
methods:{
onClick(){
// 定义一个点击事件进行传值
// 每一个vue实例 他都会有一个$emit方法,同时他也会有负责监听的一个$on方法
busData.$emit('addItem', this.title)
}
}
}
Bbro.vue
import busData from './bus'
export default {
data(){
return {
title:'this is title!' } }
mounted(){
// 在vue组件进行挂在的时候,去监听Abro.vue中定义的addItem方法
// 这个事件一旦触发的话,我们就去执行一个isComing的方法函数
busData.$on('addItem', this.isComging)
},
methods:{
isComging(title){
// title是Abro.vue传递过来的参数
console.log('title是Abro传过来的值')
}
},
beforeDestroy(){
// 组件挂在的时候进行监听,在组件销毁的时候进行一个解绑,这样就不会造成潜在内存泄漏的问题。
busData.$off('addItem', this.isComging)
}
}
版权声明
本文为[Python User]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44684357/article/details/124205621
边栏推荐
- 笔记:unordered_map的理解与使用
- QSslSocket::connectToHostEncrypted: TLS initialization failed
- DS18B20 of Blue Bridge Cup embedded expansion board learning
- Image pyramid, edge detection, image weighted display, histogram equalization
- Invalid transform origin base point setting
- STM32 learning note 3 - input pin of GPIO
- std::string 实现split
- qt打包程序打包之跨平台
- 遍历数组、对象 父子通信props/$emit
- Interaction method II between STM32 single chip microcomputer and ld3320 voice module
猜你喜欢

Universal timer

STM32 learning note 2 - set GPIO register to realize running water lamp

jeecgboot-online在线开发2

After compiling the official program of punctual atom stm32f429, it cannot be downloaded with j-link

jeecgboot-online表单开发-控件配置

STL学习笔记0x0001(容器分类)

The 7th Blue Bridge Cup embedded provincial competition: analog liquid level detection and alarm system "

Access problems after setting up the local server

动态内存管理、文件操作、预处理

jeecgboot开发经验过程
随机推荐
Photoresist for learning of Blue Bridge Cup embedded expansion board
QQueue使用介绍
chorme调试工具
cmd
IWDG
QSS、QDateEdit、QCalendarWidget自定义设置
Setting time and date display of QT learning
STM32 learning note 3 - input pin of GPIO
Intel SGX thread lock
opencv代码
Preliminary study on the principle of robot grasping objects
指针所指的地址值及指针所指对象的值(学习笔记)
Geojson file ShapeFile file batch conversion gadget
C learning experience of commission, thread and timer
ADC key for learning of Blue Bridge Cup embedded expansion board
STM32 learning note 5 - Calculation of relative position of RGB screen
QToolButtom、QPushButtom添加QMenu后去掉右下角三角图标
通用定时器
JSON.
jeecgboot-online錶單開發-控件配置