在使用splice删除数组多个元素的时候遇见,选中的删除不干净。不能全部删除
解决方法:
使用反循环
注:这里是双重循环,
正常应该先循环storageList,这里先循环newDel,最后在删除元素。
for(let i=0;i<this.newDel.length;i++){
for (let j = 0; j < this.storageList.length; j++) {
if(this.newDel[i] === this.storageList[j].prod_id){
this.storageList.splice(j,1)
}
}
}
还有一种方法可以试试
使用sort方法把需要删除的数组,先排倒序(从后往前删)
附上sort方法
arr.sort((a,b)=>{
return b-a
})