1👍
You have multiple options here:
- You can use
this.$root.$emit
and then event will be sent to all components at once, you can listen to it asthis.$root.$on
- You can create
eventBus
as explained here and then use it wherever you need to:
// The most basic event bus
// Imprt vue.js
import Vue from 'vue';
// Create empty vue.js instance to use as event bus
const Bus = new Vue({});
// Export event bus instance
export default Bus;
// Using the most basic event bus
import Vue from 'vue';
import Bus from './basic';
Vue.component('my-first-component', {
methods: {
sampleClickAction() {
Bus.$emit('my-sample-event');
}
}
});
Vue.component('my-second-component', {
created() {
Bus.$on('my-sample-event', () => {
// Do something…
});
}
});
- [Vuejs]-Passing a Variable in vue.js Component Modal Window
- [Vuejs]-Load data already registered in a form – VueJS – Bootstrap-Vue
Source:stackexchange.com