0👍
One can use a global event bus component with publish/subscribe pattern.
Here is a
post describing how it works.
To sum up, create a global component:
// eventbus.js
import Vue from 'vue';
export const EventBus = new Vue();
Use it in the publisher component:
//publisher.js
// ...
methods: {
publishEvent() {
EventBus.$emit('topic',this.dataPublished);
} }
Consume data in the listener component:
// listener.js
const eventHandler = function(data) { console.log(`Oh, that's nice. It's gotten ${data} ! :)`) }
// Listen to the event.
EventBus.$on('topic', eventHandler);
- [Vuejs]-How Show Variable in onchange Method in VueJS?
- [Vuejs]-Update element's text when $emit function has been triggered
Source:stackexchange.com