当我在父组件中更改道具时,道具不会更新
父组件:
我有controlData值作为子组件道具的默认值,control它是相等2的,当我第一次运行我的应用程序时我可以看到该值
data() {
return {
controlData: 2
}
}
在ready()我需要从后端加载数据并将该值设置为子组件道具control等于来自后端的数据。
但是可以说,现在我只想control在父组件准备好时更改(子值)。所以我在父组件中做了这个:
ready() {
this.controlData = 55;
}
controlData然后我使用 v-bind 在更改时将该值发送给子级
<child-component :control="controlData"></child-componenet>
子组件:
我的子组件中有这个
export default Bar.extend({
props: ["control"],
ready() {
console.log(this.control); // I see only default value "2" not "55" - but I expect to see "55" because I changed that value in ready() of parent
}
})
我还添加watch: {}了查找更改,props但我看不到更改
watch: {
control() {
console.log("Control is changed"); // I don't see this message when I change controlData value in parent and then by v-bind:control="controlData" i send that data in child component
}
}