|
@@ -202,6 +202,15 @@
|
|
|
|
|
|
7. 注意:通过```this.$refs.xxx.$on('atguigu',回调)```绑定自定义事件时,回调<span style="color:red">要么配置在methods中</span>,<span style="color:red">要么用箭头函数</span>,否则this指向会出问题!
|
|
|
|
|
|
+7. **特别注意**使用```this.$refs.xxx.$on('atguigu',回调)```比使用@直接绑定有优势
|
|
|
+```js
|
|
|
+// 像这样可以相应两次atguigu事件,但是使用@则不行
|
|
|
+this.$refs.student.$on('atguigu',this.getStudentName) //绑定自定义事件
|
|
|
+this.$refs.student.$on('atguigu',()=>{
|
|
|
+ console.log("qwe");
|
|
|
+})
|
|
|
+```
|
|
|
+
|
|
|
## 全局事件总线(GlobalEventBus)
|
|
|
|
|
|
1. 一种组件间通信的方式,适用于<span style="color:red">任意组件间通信</span>。
|