使用some刪除:
1 delete(id){ 2 //根據id找出索引, 3 //如果找到索引直接調用數組splice方法 4 this.list.some((item,i) => { 5 if(item.id==id){ 6 this.list.splice(i,1) 7 return true; 8 } 9 })
使用findIndex:
1 // findIndex直接找出索引,再根據索引刪除數據 2 // findIndex只是用來查找索引 3 var index= this.list.findIndex(item =>{ 4 if(item.id==id){ 5 return ture; 6 } 7 this.list.splice(indedx,1) 8 })