最近在将字符串分割成数组时总会出现问题,经过查找发现当字符串只有一个时,不能进行正确的分割,
解决方法
只需要在进行分割时单独将不需要分割的字符串进行单独处理即可
代码如下:
this.list.map(item=>{
if(item.reportLabel && typeof item.reportLabel == "string"){
if(item.reportLabel.indexOf(',')!=-1 ){
item.reportLabel = (item.reportLabel.split(',')).slice(0,4)
}else{
item.reportLabel = [item.reportLabel]
}
}
})