当前位置:网站首页>什么是全局事件总线?
什么是全局事件总线?
2022-07-25 10:52:00 【刘家奕_】
目录
第三步,在school.vue里改变 sendSchoolName()
之前的代码可见点击跳转
可以实现任何组件之间的数据交流
第一步,要认所有的组件看见一个共同东西我们叫----bus
bus不仅仅有公交车的意思,还有

在main.js里
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; //安装全局事件总线
},
});
这段代码是主要的:
beforeCreate() {
Vue.prototype.$bus = this; //安装全局事件总线
},
第二步,在student.vue里加上
mounted() {
this.$bus.$on("hello", (data) => {
console.log("收到了school数据", data);
});
},第三步,在school.vue里改变 sendSchoolName()
sendSchoolName() {
// this.$emit("liujiayi", this.schoolName);
this.$bus.$emit("hello", this.schoolName);
},
已经完成了大部分

最后,
最好加上这段代码,解绑

beforeDestroy() {
this.$bus.$off("hello");
},
边栏推荐
- Shell Chapter 7 exercise
- Oracle parsing XML with the same name
- What kind of product power does Hongguang miniev, the top seller of new energy, have?
- Breadth first traversal (problems related to sequence traversal of graphs and binary trees)
- Eigenvalues and eigenvectors of matrices
- 论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》
- LVS load balancing lvs-nat building Web Cluster
- 基于cornerstone.js的dicom医学影像查看浏览功能
- Wiznet embedded Ethernet technology training open class (free!!!)
- Several common PCB surface treatment technologies!
猜你喜欢

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

小区蔬菜配送的小程序

城市雕塑典型作品信息管理系统(图片分享系统SSM)

【电子器件笔记5】二极管参数和选型

教你如何通过MCU配置S2E为TCP Server的工作模式
![[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training](/img/c8/fe18308ddad5cb2fbccb79d2d8a2b6.png)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training

基于MATLAB的常见线性调制方法

The most efficient note taking method in the world (change your old version of note taking method)

Reinforcement learning (IV)

Eigenvalues and eigenvectors of matrices
随机推荐
将字符串转换为数字
LVS负载均衡之LVS-NAT搭建Web群集
WIZnet W5500系列培训活动之“MQTT协议讲解和实践(接入OneNET)”
Oracle parsing XML with the same name
[leetcode brush questions]
Let sports happen naturally, and fire creates a new lifestyle
Convert string to number
Signal and slot mechanism ==pyqt5
矩阵的特征值和特征向量
世界上最高效的笔记方法(改变你那老版的记笔记方法吧)
SQL注入 Less17(报错注入+子查询)
大话DevOps监控,团队如何选择监控工具?
cookie and session
黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
相似矩阵,可对角化条件
全网显示 IP 归属地,是怎么实现的?
Multiply Floyd "suggestions collection"
SQL language (III)
SQL language (4)
Learn Luzhi PHP -- tp5.0 uses Chinese as an alias and reports "unsupported data expression"