Created
January 9, 2019 15:32
-
-
Save ppscvalentin/4b05e7e82a7b4386f2aaf9ba818254b0 to your computer and use it in GitHub Desktop.
Vue EventBus to couple components loosely
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 EventBus from 'Events.js' | |
export default { | |
... | |
mounted() { | |
EventBus.$emit('eventName', payload); | |
} | |
... | |
} |
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'; | |
const EventBus = new Vue(); | |
export default EventBus; |
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
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