| 1 |
const eventBus = Vue.reactive({}); |
| 2 |
|
| 3 |
eventBus.on = function (event, callback) { |
| 4 |
if (!this[event]) this[event] = []; |
| 5 |
this[event].push(callback); |
| 6 |
}; |
| 7 |
|
| 8 |
eventBus.emit = function (event, payload) { |
| 9 |
if (this[event]) { |
| 10 |
this[event].forEach((callback) => callback(payload)); |
| 11 |
} |
| 12 |
}; |
| 13 |
|
| 14 |
export default eventBus; |