Skip to content

Instantly share code, notes, and snippets.

@RuslanHolovko
Created October 5, 2019 15:31
Show Gist options
  • Save RuslanHolovko/f6318dcbd584643014efd6af0ad26515 to your computer and use it in GitHub Desktop.
Save RuslanHolovko/f6318dcbd584643014efd6af0ad26515 to your computer and use it in GitHub Desktop.
Event bus emit vue js
// create eBus variable in main.js
export const eBus = new Vue();
// import ebus to component
import {eBus} from '../main'
methods:{
changeName () {
//create custom event
eBus.$emit('CHANGE_NAME', this.userName);
}
}
// subscribe to custom event CHANGE_NAME event
import {eBus} from '../main'
mounted(){
eBus.$on('CHANGE_NAME', (payload) => {
this.userNameProfile = payload;
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment