今天渲染节点的时候,发现整个页面的数据都给我显示不出来了
控制台打印报错信息
原因是后端返回了一个null给我,而这里本身应该是字符串、数组、或者对象的, 但他硬要给我返回null,让他改成正确的格式他页不改,只能前端想办法处理了




前端解决方案:
第1种、赋值的时候手动判断内容是否为null,如果是null的话把它修改成对应的格式
if (res.data.search == null) {
this.historySource = [];
} else {
this.historySource = res.data.search;
console.log("historySource", this.historySource);
}
第2种、在页面渲染的标签中,用三元表达式判断这个标签是否为null,如果是的话就让渲染对应格式的空内容,如果不是null的话就渲染该数据
<img
:src="item.course == null ? '' : item.course.image"
alt=""
width="236"
height="134"
v-focusable
/>
Comments | NOTHING