当前位置:网站首页>What is the global event bus?
What is the global event bus?
2022-07-25 11:49:00 【Liu Jiayi_】
Catalog
First step , To recognize that all components see a common thing, we call it ----bus
The second step , stay student.vue Riga
The third step , stay school.vue Change in sendSchoolName()
The previous code is visible Click the jump
It can realize the data exchange between any components
First step , To recognize that all components see a common thing, we call it ----bus
bus It's not just about buses , also

stay main.js in
import Vue from "vue";
import App from "./App.vue";
Vue.config.productionTip = false;
new Vue({
el: "#app",
render: (h) => h(App),
beforeCreate() {
Vue.prototype.$bus = this; // Install the global event bus
},
});
This code is the main :
beforeCreate() {
Vue.prototype.$bus = this; // Install the global event bus
},
The second step , stay student.vue Riga
mounted() {
this.$bus.$on("hello", (data) => {
console.log(" received school data ", data);
});
},The third step , stay school.vue Change in sendSchoolName()
sendSchoolName() {
// this.$emit("liujiayi", this.schoolName);
this.$bus.$emit("hello", this.schoolName);
},
Most of the work has been done

Last ,
You'd better add this code , Unbundling

beforeDestroy() {
this.$bus.$off("hello");
},
边栏推荐
- Activity registration | play with kubernetes container service improvement class officially opened!
- JS数据类型以及相互转换
- 活动报名 | 玩转 Kubernetes 容器服务提高班正式开营!
- 擎创科技加入龙蜥社区,共建智能运维平台新生态
- flinksql client 连接kafka select * from table没有数据报错,如何解决?
- 相似矩阵,可对角化条件
- SQL injection less23 (filter comment)
- Oil monkey script link
- Oracle parsing XML with the same name
- 谣言检测文献阅读十一—Preventing rumor spread with deep learning
猜你喜欢

Javescript loop

工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖

SQL language (II)

Filter过滤器解决request请求参数乱码的原理解析

教你如何通过MCU配置S2E为TCP Client的工作模式

阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程

Teach you how to configure S2E as the working mode of TCP client through MCU

黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。

Reinforcement learning (IV)

【USB设备设计】--复合设备,双HID高速(64Byte 和 1024Byte)
随机推荐
JVM performance tuning methods
Various controls ==pyqt5
Use three.js to realize the cool cyberpunk style 3D digital earth large screen
动态规划问题03_最大子段和
Database integrity -- six constraints learning
Attendance system based on w5500
W5500 multi node connection
【mysql学习08】
Teach you how to configure S2E as the working mode of TCP server through MCU
【MySQL 17】安装异常:Could not open file ‘/var/log/mysql/mysqld.log‘ for error logging: Permission denied
信号与槽机制==PYQT5
JS data types and mutual conversion
Job interviews are always a second kill? After reading the seckill system notes secretly stored by JD T8, I have given my knees
第一个C语言程序(从Hello World开始)
活动报名 | 玩转 Kubernetes 容器服务提高班正式开营!
Reflection reflection
Dynamic planning question 05_ Missile interception
基于MATLAB的常见线性调制方法
动态规划问题05_导弹拦截
Layout management ==pyqt5