Skip to content

Instantly share code, notes, and snippets.

@shentao
Last active June 15, 2018 18:24
Show Gist options
  • Save shentao/d299b0e3292bbbc161827efe2c5c3da0 to your computer and use it in GitHub Desktop.
Save shentao/d299b0e3292bbbc161827efe2c5c3da0 to your computer and use it in GitHub Desktop.
Vue EventBus Example
// 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