当前位置:网站首页>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");
},
边栏推荐
猜你喜欢

Talking about Devops monitoring, how does the team choose monitoring tools?

常见WEB攻击与防御

论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》

油猴脚本链接

SQL language (4)

Functions in JS

Summary of combination problems of Li Kou brush questions (backtracking)

Leetcode sword finger offer 28. symmetric binary tree

W5500上传温湿度到oneNET平台

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)
随机推荐
[MySQL learning 08]
SQL language (V)
Common linear modulation methods based on MATLAB
【mysql学习09】
大话DevOps监控,团队如何选择监控工具?
Flinksql client connection Kafka select * from table has no data error, how to solve it?
"Mqtt protocol explanation and Practice (access to onenet)" of wiznet w5500 series training activities
Functions in JS
Fillet big killer, use filter to build fillet and wave effect!
How does the whole network display IP ownership?
擎创科技加入龙蜥社区,共建智能运维平台新生态
[electronic device notes 5] diode parameters and selection
Eigenvalues and eigenvectors of matrices
[leetcode brush questions]
基于cornerstone.js的dicom医学影像查看浏览功能
W5500 upload temperature and humidity to onenet platform
【MySQL 17】安装异常:Could not open file ‘/var/log/mysql/mysqld.log‘ for error logging: Permission denied
Management of software defects
Use three.js to realize the cool cyberpunk style 3D digital earth large screen
相似矩阵,可对角化条件