1. 程式人生 > >vue中使用some刪除list中的資料

vue中使用some刪除list中的資料

在vue中可以使用some方法查詢需要刪除的所以

this.list.some((item, i) => {
    if (item.id == id) {
        this.list.splice(i, 1)
        return true;
    }
})

也可使用findIndex方法

var index = this.list.findIndex(item => {
    if (item.id == id){
        return true;
    }
})

this.list.splice(index, 1)