JSFiddle - React, Tailwind, and code Playground
by rjurado
HTML
<div id="app">
<my-component></my-component>
<button @click="click">Click</button>
</div>
JavaScript
var Child = {
template: '<div>{{value}}</div>',
data: function () {
return {
value: 0
};
},
methods: {
setValue: function(value) {
this.value = value;
}
},
created: function() {
this.$parent.$on('update', this.setValue);
}
}
new Vue({
el: '#app',
components: {
'my-component': Child
},
methods: {
click: function() {
this.$emit('update', 7);
}
}
})