Vue
by Ryoya Tamura
HTML
<div id="app">
</div>
Vue
const s = Symbol();
const Child = Vue.extend({
inject: { s },
template: `<div>child: {{s}}</div>`
});
const Parent = Vue.extend({
data() {
return {
value: 0,
};
},
components: {
Child,
},
provide() {
return {
[s]: this.value,
};
},
methods: {
countup() {
this.value++;
},
},
template: `<div><button @click="countup">Count-up</button><Child /><pre>parent: {{value}}</pre></div>`,
});
new Vue({
el: "#app",
components: {
Parent,
},
template: `<Parent />`,
});