当前位置:网站首页>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
边栏推荐
- Self incrementing sequence creation of MySQL
- Qingdao agile tour, coming!
- SQL Server检索SQL和用户信息的需求
- 源码剖析Redis中如何使用跳表的
- Three of three JS (WEB GL) model deletion / scene emptying / simple sorting of memory release
- Devops life cycle, all you want to know is here!
- Uniapp hot update with progress bar
- 2021-10-12
- [untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength
- Laravel database
猜你喜欢

2022年最热门的招聘技术技能是什么,您绝对想不到

Traversal of tree

Blender programmed terrain production
![[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength](/img/94/37d80984fe6fad84e73c2f8e6b2d52.jpg)
[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength

狼叔来找翻译人员了--plato--持续翻译中.....

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

7-4 is it too fat (10 points) PTA

selenium預先加載cookie的必要性

无线网怎么用手机验证码登录解决方案

Open source rule engine - Ice: dedicated to solving flexible and complex hard coding problems
随机推荐
看板快速启动指南
Knowledge of egg testing -- mock, Supertest, coffee
数字化转型失败,有哪些原因?
2021-11-08
即将毕业的大学生找技术开发工作的焦虑根源
The 2021 IT industry project management survey report was released!
MFC实现资源单独Dll实现
2021-10-12
2021-10-08
2021-09-27
d. TS --- for more detailed knowledge, please refer to the introduction on the official website (chapter of declaration document)
Basic use of sqlyog
Redis的基本知识
2021-09-23
JS time format conversion
selenium预先加载cookie的必要性
What are the reasons for the failure of digital transformation?
MFC implementation resources are implemented separately by DLL
Qingdao agile tour, coming!
Collaboration future object and concurrent futures