当前位置:网站首页>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");
},
边栏推荐
- 【USB设备设计】--复合设备,双HID高速(64Byte 和 1024Byte)
- SQL injection less17 (error injection + subquery)
- How to solve the problem that "w5500 chip cannot connect to the server immediately after power failure and restart in tcp_client mode"
- [MySQL learning 08]
- W5500在处于TCP_Server模式下,在交换机/路由器网络中无法ping通也无法通讯。
- SQL injection less23 (filter comment)
- JS中的对象
- JS中的函数
- Teach you how to configure S2E to UDP working mode through MCU
- Emmet syntax quick query syntax basic syntax part
猜你喜欢

Attendance system based on w5500

【mysql学习08】

任何时间,任何地点,超级侦探,认真办案!

JS运算符

varest蓝图设置json

JS中的函数

SQL injection less23 (filter comment)

Game backpack system, "inventory Pro plug-in", research and learning ----- mom doesn't have to worry that I won't make a backpack anymore (unity3d)

小区蔬菜配送的小程序

【IMX6ULL笔记】--内核底层驱动初步探究
随机推荐
Eigenvalues and eigenvectors of matrices
什么是全局事件总线?
toString()与new String()用法区别
SQL injection less23 (filter comment)
Introduction to shortcut keys in debug chapter
Functions in JS
城市雕塑典型作品信息管理系统(图片分享系统SSM)
"Mqtt protocol explanation and Practice (access to onenet)" of wiznet w5500 series training activities
数据库完整性——六大约束学习
flinksql client 连接kafka select * from table没有数据报错,如何解决?
Onenet platform control w5500 development board LED light
Plot ==pyqt5
Hardware peripherals =maixpy3
Teach you how to configure S2E to UDP working mode through MCU
Esp8266 uses drv8833 drive board to drive N20 motor
Varest blueprint settings JSON
基于MATLAB的常见线性调制方法
Make a reliable delay queue with redis
Flinksql client connection Kafka select * from table has no data error, how to solve it?
SQL injection less17 (error injection + subquery)