Vue
by Damian Dulisz
HTML
<div id="app">
<h2>My Comp:</h2>
<div v-once>
y = {{ y }} (this won’t rerender)
<hr>
Child can update itself am:
<my-comp :y="y" />
</div>
<hr>
<button @click="y.value++">
y++ {{ y }}
</button>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
const MyComp = {
props: { y: Object },
data () {
return {
x: 0
}
},
render (h) {
return h('div', {}, [
h('button', { on: { click: () => this.x++ } }, `x = ${this.x }`),
`x + y = ${this.x + this.y.value}`
])
}
}
new Vue({
components: { 'my-comp': MyComp },
el: "#app",
data: {
y: { value: 0 },
},
})