响应数据为null或"" 时 返回暂无
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
}
处理axios返回值的函数
function mapResultData(data) {
if (Array.isArray(data)) {
mapArrData(data)
}
if (isObject(data)) {
mapNullData(data)
}
return data
}
处理对象类型数据
function mapNullData(inObject) {
let inObjectKeysArr = Object.keys(inObject)
inObjectKeysArr.forEach(key => {
if (isObject(inObject[key])) {
mapNullData(inObject[key])
} else if (Array.isArray(inObject[key])) {
mapArrData(inObject[key])
} else if (inObject[key] == null || inObject[key] == '') {
inObject[key] = '暂无'
} else {
'inObject[key]'
}
})
return inObject
}
处理数组类型数据
function mapArrData(inArr) {
inArr.forEach(item => {
if (isObject(item)) {
mapNullData(item)
} else if (Array.isArray(item)) {
mapArrData(item)
} else {
'item'
}
})
}