处理后端返回数据的时候,有时候会不给返回某个对象的属性为空的情况;这个时候如果需要前端处理的话,需要用到obj自带的方法 Object.hasOwnProperty.call(判断的对象," 判断对象的属性") ,如果有这个属性,返回 true;没有这个属性,就返回 false
if (Object.hasOwnProperty.call(res.data, "errorLog")) {
if (
JSON.stringify(res.data.errorLog).slice(
1,
JSON.stringify(res.data.errorLog).length - 1
).length
) {
showData.push(
"*******构建失败日志*******",
JSON.stringify(res.data.errorLog).slice(
1,
JSON.stringify(res.data.errorLog).length - 1
)
);
} else {
showData.push("*******构建失败日志*******", "无");
}
} else {
// return;
}