data:{
uploadimgs: []
}
that.uploadimgs.concat(res.tempFilePaths) 使用正常
that.uploadimgs.remove(e.currentTarget.dataset.index)//使用异常
page handleProxy function TypeError: this.uploadimgs.remove is not a function
重写后concat使用异常
Array.prototype.remove = function(i){
const l = this.length;
if(l==1){
return []
}else if(i>1){
return [].concat(this.splice(0,i),this.splice(i+1,l-1))
}
}
2 个回复
l***@foxmail.com (作者)
已解决,重写扩展remove方法
Array.prototype.remove=function(obj){
for(var i =0;i <this.length;i++){
var temp = this[i];
if(!isNaN(obj)){
temp=i;
}
if(temp == obj){
for(var j = i;j <this.length;j++){
this[j]=this[j+1];
}
this.length = this.length-1;
}
}
}
Trust - 少说废话
js Array 没有 remove 方法。。。移除某一项,用的 splice。
http://www.w3school.com.cn/jsref/jsref_splice.asp