[英]VueJS 1.0.8 - Remove object from array based on index
我正在將項目升級到Vue 1.0。 我有以下格式的對象數組:
data: {
shifts: {
'43' : {
userId: 43,
name: 'Frank'
},
'90' : {
userId: 90,
name: 'Martha'
}
}
}
在1.0之前,要刪除一個對象,我會使用this.shifts.$delete('90')
刪除該對象。 這不再有效,我不清楚替換是什么。 我也試過this.$remove(this.shifts, '90')
, Vue.$remove(this.shifts, '90')
等。
此外, $add
被棄用,取而代之的$set
,但我無法弄清楚如何添加一個新的對象(如'95: { userId: 95, name: 'John' }
以$set
。
非常令人沮喪,任何幫助將不勝感激。
你可以試試這個,
// to set
Vue.set(this.shifts, '95', {userId: 95, name: 'John'})
// to delete
Vue.delete(this.shifts, '95')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.