当前位置:网站首页>Data bus realizes the communication between brother components
Data bus realizes the communication between brother components
2022-04-23 05:25:00 【Python User】
Define a data bus bus.js,Abro Give the components to Bbro Component transfer value
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(){
// Define a click event for value transfer
// every last vue example He will have one $emit Method , At the same time, he will also have a person in charge of monitoring $on Method
busData.$emit('addItem', this.title)
}
}
}
Bbro.vue
import busData from './bus'
export default {
data(){
return {
title:'this is title!' } }
mounted(){
// stay vue When the component is hung , To monitor Abro.vue As defined in addItem Method
// Once this event is triggered , Let's go and perform a isComing The method function of
busData.$on('addItem', this.isComging)
},
methods:{
isComging(title){
// title yes Abro.vue The parameters passed in
console.log('title yes Abro Transmitted value ')
}
},
beforeDestroy(){
// Listen when the component is hung , Perform a unbinding when the component is destroyed , This will not cause potential memory leaks .
busData.$off('addItem', this.isComging)
}
}
版权声明
本文为[Python User]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220544564657.html
边栏推荐
- Three of three JS (webgl) simple sorting of rotation attribute function, and a simple case of rotating around the axis based on this
- App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
- If the route reports an error after deployment according to the framework project
- 2021 年 25 大 DevOps 工具(下)
- egg测试的知识大全--mock、superTest、coffee
- SQL Server检索SQL和用户信息的需求
- Master-slave replication of MariaDB database
- Interpretation of common SQL statements
- 学习笔记:Unity CustomSRP-10-Point and Spot Shadows
- Knowledge of egg testing -- mock, Supertest, coffee
猜你喜欢

What are the most popular recruitment technical skills in 2022? You can't think of it

(十一)vscode代码格式化配置
![Laravel [view]](/img/39/71db98d8832d9419bcc1097594d1b6.png)
Laravel [view]

云计算与云原生 — OpenShift 的架构设计

看板快速启动指南

Excel 2016 打开文件第一次打不开,有时空白,有时很慢要打开第二次才行

How to set the initial value of El input number to null

Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)

Anti crawler (0): are you still climbing naked with selenium? You're being watched! Crack webdriver anti crawler

Using PHP post temporary file mechanism to upload arbitrary files
随机推荐
JS array common methods
FileReader API file operation
SQL Server检索SQL和用户信息的需求
What are the reasons for the failure of digital transformation?
Anti crawler (0): are you still climbing naked with selenium? You're being watched! Crack webdriver anti crawler
es6数组的使用
Low code and no code considerations
好的测试数据管理,到底要怎么做?
Study notes: unity customsrp-11-post processing --- bloom
Three 之 three.js (webgl)模型的删除/场景的清空/内存的释放 的简单整理
2021-09-27
青岛敏捷之旅,来了!
即将毕业的大学生找技术开发工作的焦虑根源
Study notes: unity customsrp-10-point and spot shadows
使用 Kears 实现ResNet-34 CNN
《2021年IT行业项目管理调查报告》重磅发布!
Three 之 three.js (webgl)旋转属性函数的简单整理,以及基于此实现绕轴旋转的简单案例
JSP -- Introduction to JSP
了解 DevOps,必读这十本书!
JVM memory and memory overflow exceptions (personal summary)