Last active
June 15, 2018 18:24
-
-
Save shentao/d299b0e3292bbbc161827efe2c5c3da0 to your computer and use it in GitHub Desktop.
Vue EventBus Example
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
// EventBus.js | |
export const eventBus = new Vue() | |
// FileA.js | |
import { EventBus } from './EventBus' | |
const x = 'my param' | |
EventBus.$emit('event-name', x) | |
// FileB.js | |
import { EventBus } from EventBus | |
EventBus.$on('event-name', param => { | |
console.log(param) // will log 'my param' whenever line #9 is called | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment