简体   繁体   中英

VueJS 1.0.8 - Remove object from array based on index

I am in the process of upgrading a project to 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. 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.

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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