///这样写虽然可以但是最好是自己写一个方法封装一下,因为这样写的方法虽然也可以用,但是会出现污染变量的情况
Array.prototype.remove = function(val) {
let index = -1;
for (let i = 0; i < this.length; i++) {
if (this[i].uid === val) {
index = i;
}
}
console.log("index" + index);
if (index > -1) {
this.splice(index, 1);
}
};
fileArr.remove(ind);
//或者简单的:
arr.splice( arr.indexOf( null ), 1 );
//这是我封装的方法
fileRemove(obj, id) {
let index = -1;
for (let i = 0; i < obj.length; i++) {
if (obj[i].uid === id) {
index = i;
}
}
if (index > -1) {
obj.splice(index, 1);
}
return obj;
},
//其他地方
this.fileList=this.fileRemove(this.fileList,file.uid);