前提:let aa =null; aa 在开发环境是字符串类型,但是在测试环境、生产环境是数组类型。要针对不同得类型做不同得操作。
if(aa){ //要先判断是否为空
if (typeof aa === 'string') {
console.log('aa 是字符串');
let tempData=aa.split(',') //分割,成数组
this.params=tempData
} else if (Array.isArray(aa)) {
console.log('aa 是数组');
this.params=aa
} else {
console.log('aa 既不是字符串也不是数组');
}}
追加:判断是不是空字符串
aa.trim() 去除字符串首尾空格后判断是否为空字符串。