简体   繁体   English

VueJS 1.0.8 - 根据索引从数组中删除对象

[英]VueJS 1.0.8 - Remove object from array based on index

I am in the process of upgrading a project to Vue 1.0. 我正在将项目升级到Vue 1.0。 I have an array of objects in the following format: 我有以下格式的对象数组:

data: {
shifts: {
            '43' : {
                userId: 43,
                name: 'Frank'
            },
            '90' : {
                userId: 90,
                name: 'Martha'
            }
        }
}

Prior to 1.0, to remove an object, I would use this.shifts.$delete('90') to delete that object. 在1.0之前,要删除一个对象,我会使用this.shifts.$delete('90')删除该对象。 This no longer works and it is unclear to me what the replacement is. 这不再有效,我不清楚替换是什么。 I have also tried this.$remove(this.shifts, '90') , Vue.$remove(this.shifts, '90') , etc. 我也试过this.$remove(this.shifts, '90')Vue.$remove(this.shifts, '90')等。

Also, $add was deprecated in favor of $set but I cannot figure out how to add a new object (such as '95: { userId: 95, name: 'John' } ) with $set . 此外, $add被弃用,取而代之的$set ,但我无法弄清楚如何添加一个新的对象(如'95: { userId: 95, name: 'John' }$set

Very frustrating, any help would be appreciated. 非常令人沮丧,任何帮助将不胜感激。

You could try this, 你可以试试这个,

// to set
Vue.set(this.shifts, '95', {userId: 95, name: 'John'})
// to delete
Vue.delete(this.shifts, '95')

http://codepen.io/pespantelis/pen/PPLJKP http://codepen.io/pespantelis/pen/PPLJKP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM