【发布时间】:2020-02-14 03:38:22
【问题描述】:
我是新的 vue js。我不知道为什么当我更改父组件中的值时子组件中的值不会更新。谁能为我解释一下?我知道我可以使用Times Updated: {{ times}} 来显示。但我想把它分配给 count 做别的事情
父母 HTML
<div id="test">
<button @click="clicktime">Click</button>
<times-updated :times.sync="myData"></times-updated>
</div>
.js 文件
var vm = new Vue({
el: '#test',
data(){
return {
myData: 100
}
},
methods: {
clicktime() {
vm.myData = Math.random();
}
}
})
孩子
Vue.component('times-updated', {
props:["times"],
data() {
return {
count: this.times
}
},
template: '<span>Times Updated: {{ count }}</span>',
});
链接codepen:enter link description here
【问题讨论】:
标签: vue.js