1)In VueJs
2.0 communication between components using a single event hub
-Define centralized event hub.
const eventHub = new Vue() // Single event hub
// Distribute to components using global mixin
Vue.mixin({
data: function () {
return {
eventHub: eventHub
}
}
})
-Now in your component you can emit events with
this.eventHub.$emit('update', data)
-And to listen you do
this.eventHub.$on('update', data => {
// do your thing
})