Skip to content

Instantly share code, notes, and snippets.

@andreipfeiffer
Last active February 2, 2017 11:53
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 andreipfeiffer/a3837b5bcdd80c2a8707dc48b52819fb to your computer and use it in GitHub Desktop.
Save andreipfeiffer/a3837b5bcdd80c2a8707dc48b52819fb to your computer and use it in GitHub Desktop.
// global Event Bus
const eventBus = new Vue();
/* ... */
// some deeply nested component
methods: {
onClick() {
// emit a custom event on the Event Bus, not on "this" component
eventBus.$emit('save');
}
}
/* ... */
// any other component
mounted() {
// subscribe to event on the Event Bus
eventBus.$on('save', () => {/**/});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment