道具的變化,當我在父組件改變他們VueJS - 道具不更新子組件由父母不更新
父組件:
我controlData
值作爲子組件defaul值託control
等於2
,我可以看到,值當我運行我的應用程序第一次
data() {
return {
controlData: 2
}
}
在ready()
我需要從後端加載數據,並將該值設置爲等於來自後端的數據的子組件prop control
。
但讓我們說,現在我只想在父組件準備就緒時更改control
(子值)。所以我在父組件做出這樣的:
ready() {
this.controlData = 55;
}
然後我用V-綁定到送孩子該值時controlData
改變
<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
}
}
這是Vue版本1? – Bert
是的,我們使用的是VueJS 1 –