2π
β
The easiest way will be to create global event bus. You can do it this way:
Vue.prototype.globalEvents = new Vue();
And after that you will be able to emit and listen to events from anywhere in your component tree:
methods: {
myMethod () {
this.globalEvents.$emit(...)
this.globalEvents.$on(...)
}
}
Alternatively you can create local event bus the same way, for example, create module called bus.js
:
import Vue from 'vue';
const events = new Vue();
export default { events };
And use it only in components where you want to use these events.
π€euvl
Source:stackexchange.com