JSFiddle - React, Tailwind, and code Playground
by James Doyle
HTML
<!-- template for child -->
<template id="child-template">
<input v-model="msg">
<button v-on:click="notify">Dispatch Event</button>
</template>
<!-- template for parent -->
<div id="events-example">
<p>Messages: {{ messages | json }}</p>
<child></child>
</div>
JavaScript
// register child, which dispatches an event with
// the current message
Vue.component('child', {
template: '#child-template',
data: function () {
return { msg: 'hello' }
},
methods: {
notify: function () {
if (this.msg.trim()) {
this.$dispatch('child-msg', this.msg)
this.msg = ''
}
}
}
});