Last active
April 25, 2018 07:24
-
-
Save cedeber/c062f377997ec0918b09a2f2a4a0c84a to your computer and use it in GitHub Desktop.
Vue global bus as event hub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.com/patrickleenyc/vue-js-simple-event-bus-for-cross-component-communication-85dd8f0fc750
https://vuejs.org/v2/guide/migration.html#dispatch-and-broadcast-replaced