[Vuejs]-Triggering child method (or computed property) from root – vue2

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

Leave a comment