Skip to content

Instantly share code, notes, and snippets.

@ppscvalentin
Created January 9, 2019 15:32
Show Gist options
  • Save ppscvalentin/4b05e7e82a7b4386f2aaf9ba818254b0 to your computer and use it in GitHub Desktop.
Save ppscvalentin/4b05e7e82a7b4386f2aaf9ba818254b0 to your computer and use it in GitHub Desktop.
Vue EventBus to couple components loosely
import EventBus from 'Events.js'
export default {
...
mounted() {
EventBus.$emit('eventName', payload);
}
...
}
import Vue from 'vue';
const EventBus = new Vue();
export default EventBus;
export default {
...
mounted() {
EventBus.$on('eventName', payload => {
// do your thing
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment