//当字段结构为字符串时:
res.data.storeIds = "[1, 4, 1007, 39, 38, 112, 344, 34]"
let storeIds = res.data.storeIds.slice(1,res.data.storeIds.length-1); // 截取字符串[ ] 中间的内容
if(res.data.storeIds){
storeIds = storeIds.replace(/\r/g, "\n").replace(/\s+/g, "\n"); // 将字符串中的逗号,缩进进行替换成换行 操作
}
// 输出结果为
console.log(storeIds,typeof(storeIds),'storeIds')
1,
4,
1007,
39,
38,
112,
344,
34
// 输出的类型为字符串string, storeIds
页面展示效果为这样
// 方法:换行或者空格都进行数据处理,处理成作为一个数组
export function getIdArrFun(str){
// 换行或者空格都进行转成一个数据
return str.split('\n').reduce((prev, cur) =>{
let arr = cur.trim().split(/\s+/).filter(a =>{
return a;
});
return prev.concat(arr);
}, []);
}
data(){
const data = {
// 引用方法
storeIdList: Array.from(new Set(getIdArrFun(storeIds || ''))),
};
return data;
},