vue iview Select bug,在低版本浏览器中报错

时间:2023-03-09 15:09:10
vue iview Select bug,在低版本浏览器中报错

iview是个好东西,今天第一次试用,用来做了一个app,但是在安卓5.1各种报错啊,头痛的是不知道具体哪行代码错了,总是报错undefined is not a function。

倒腾了半天,原来是iview的select中用了Array.find、array.findIndex方法。原来浏览器版本低了,不兼容这些JavaScript特性。果断的给打上补丁就好了

if(typeof Array.includes == 'undefined'){
Array.prototype.includes = function(obj){
return this.indexOf(obj) >=0
}
} if(typeof Array.findIndex == 'undefined'){
Array.prototype.findIndex = function(obj){
for(var i in this){
if(this[i] == obj){
return i;
}
}
return -1
}
}
if(typeof Array.find == 'undefined'){
Array.prototype.find = function(fn){
for(var i in this){
if(fn(this[i],i,this)== true){
return this[i];
}
}
return undefined;
}
}