Bus
It's a wrapper of mitt a simple event emitter. To learn more about mitt, read the documentation on github
Usage
vue
<script>
export default {
mounted() {
// start listening
this.$bus.on('<your-channel>', this.busListener)
},
beforeDestroy() {
// stop listening
this.$bus.off('<your-channel>', this.busListener)
},
methods: {
busListener(data) {
// do something with data
},
emitOnBus(data) {
// emit an event on the listeners
this.$bus.emit('<your-channel>', { ...data })
},
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
The two methods, on
and off
are used respectively to add/remove a listener for an event.
The method emit
is used to emit an event on the listeners.