我有2個組件 - <my-component>
和<grand-child-comp>
。在prop循環中觀察父項並不更新
在我的根目錄中有一個多維對象,我的組件用prop來觀察它。
<div id="app">
<my-component v-bind:account-types='accountTypes'>
</my-component>
</div>
在Vue調試器中,我可以看到my-component正在獲取並正在監視accountTypes對象。但是,當試圖在my-component's
模板中使用它時,它不起作用。
Vue.component('my-component', {
template: `
<div>
<grand-child-comp v-for="(account, index) in accountTypes" :key="index"></grand-child-comp>
</div>
`
}
最後,accountTypes物體看起來像:
{ 1 : [ 'a', 'b', 'c' ], 2: ['e', 'a', 'm'] }
特別是你的小提琴,你正在'accountTypes'不正確地傳遞給'my-component'。 https://jsfiddle.net/50wL7mdz/51204/ – Bert
啊。我發現了這個問題。它與初始化根中的accountTypes有關。我正在使用'accountTypes:{}'。我試圖把預定義的值,它的工作 – senty