this.$EventBus.$on
时间: 2023-10-28 22:02:13 浏览: 54
this.$EventBus.$on is a method used in Vue.js to listen for custom events. It allows components to communicate with each other by sending and receiving events.
When calling this.$EventBus.$on, you need to provide the event name as the first argument and a callback function as the second argument. The callback function will be executed when the event is emitted.
For example:
```javascript
// Component A
this.$EventBus.$on('customEvent', (data) => {
console.log('Received event:', data);
});
// Component B
this.$EventBus.$emit('customEvent', 'Hello from Component B!');
```
In the above example, Component A is listening for the 'customEvent' and will log the received data when the event is emitted from Component B using this.$EventBus.$emit.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)