Created
October 5, 2019 15:31
-
-
Save RuslanHolovko/f6318dcbd584643014efd6af0ad26515 to your computer and use it in GitHub Desktop.
Event bus emit vue js
This file contains hidden or 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
// 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