如果子组件只作显示,直接绑定prop的值就可以了。如果还有其他考虑,可以用watch
<div id="app">
<child :temp="temp"></child>
</div>
var vm = new Vue({
el: "#app",
data: {
temp: 1
},
components: {
"child": {
template: '<div>{{template}}</div>',
props: ['temp'],
data(){
return {
template: ''
}
},
watch: {
temp() {
this.template = this.temp
}
},
created(){
this.template = this.temp
}
}
},
mounted(){
this.temp = 2;
}
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…