Skip to content

Instantly share code, notes, and snippets.

@slenty
Forked from ahmadshah/componentA.vue
Created June 20, 2018 07:34
Show Gist options
  • Save slenty/ed451c4e99e21595609c64aef84afb38 to your computer and use it in GitHub Desktop.
Save slenty/ed451c4e99e21595609c64aef84afb38 to your computer and use it in GitHub Desktop.
Vuejs Event Emitter
<template>
<button @click="emitEvent">EVENT</button>
</template>
<script>
import { EV } from './events'
export default {
methods: {
emitEvent() {
EV.emit('sample-event', 'foobar')
}
}
}
</script>
<template>
<component-a></component-a>
<br>
<div>{{ msg }}</div>
</template>
<script>
import { EV } from './events'
import ComponentA from './componentA.vue'
export default {
data() {
return {
msg: null
}
},
created() {
EV.on('sample-event', (foo) => {
this.$set('msg', foo)
})
}
}
</script>
import { EventEmitter } from 'events'
export const EV = new EventEmitter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment