[Vuejs]-Parsing data from one component to another in vueJS

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);

Leave a comment