Communication between sibling components in Vue.js 2.0

With Vue.js 2.0, I'm using the eventHub mechanism as demonstrated in the documentation.

  1. Define centralized event hub.

     const eventHub = new Vue() // Single event hub
    
     // Distribute to components using global mixin
     Vue.mixin({
         data: function () {
             return {
                 eventHub: eventHub
             }
         }
     })
    
  2. Now in your component you can emit events with

     this.eventHub.$emit('update', data)
    
  3. And to listen you do

     this.eventHub.$on('update', data => {
     // do your thing
     })
    

Update

Please see the answer by alex, which describes a simpler solution.


You can even make it shorter and use the root Vue instance as the global Event Hub:

Component 1:

this.$root.$emit('eventing', data);

Component 2:

mounted() {
    this.$root.$on('eventing', data => {
        console.log(data);
    });
}