Skip to content

Instantly share code, notes, and snippets.

@cedeber
Last active April 25, 2018 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedeber/c062f377997ec0918b09a2f2a4a0c84a to your computer and use it in GitHub Desktop.
Save cedeber/c062f377997ec0918b09a2f2a4a0c84a to your computer and use it in GitHub Desktop.
Vue global bus as event hub
import Vue from "vue";
// Create the event bus by creating a new Vue instance and
// binding it somehwere accessible. If you bind it to the
// Vue prototype, you can access it within your components
// like this:
//
// Emit an event
// this.$bus.$emit('myEvent', {data: true})
//
// React to an event
// this.$bus.$on('myEvent', (message) => {console.log(message})
Vue.prototype.$bus = new Vue({})