我有一個根和一個子組件。我試圖使用從父母到孩子的道具傳遞數據。我可以看到我的組件有accountTypes但id不顯示。雖然將數據從父項傳遞給了子項,但它通過但未獲取更新
的對象結構是這樣的:
var obj = {
1 : [ "a", "z", "k", "m" ]
2 : [ "a", "b", "c", "d" ]
}
而在我的主要的應用程序,
var app = new Vue({
el: '#root',
data: {
accountTypes : {},
},
methods : {
// selecting & pushing
accountTypeSelected(clientIndex, formName, action) {
if (action == 'add') {
this.pushValue(clientIndex, formName)
} else {
this.removeFromArray(clientIndex, formName)
}
},
// And these are what I use for push and delete:
pushValue(key, value) {
var obj = this.accountTypes
if (obj.hasOwnProperty(key)) {
var idx = $.inArray(value, obj[key]);
if (idx == -1) {
obj[key].push(value);
}
} else {
obj[key] = [value];
}
},
removeFromArray(key, val) {
var idx = $.inArray(val, this.accountTypes[key]);
if (idx != -1) {
this.accountTypes[key].splice(idx, 1);
}
}
}
1:{「a」,「z」,「k」,「m」} ???不是數組? 1:[「a」,「z」,「k」,「m」],沒有鍵/值對,所以數組 –
你在'v-bind'中有問題。 它應該是'<我的組分 V-綁定:accountTypes = 'accountTypes'> 我的組分>' 參見: https://vuejs.org/v2/guide/syntax.html#v - 綁定 - 速記 –
對不起。他們是陣列。另外,對'v-bind:'的類型感到抱歉。現在解決它們,但事實並非如此。感謝您指出 – senty