TypeError: Cannot read property ‘length‘ of null
程序员文章站
2022-06-07 13:20:09
...
参考如下代码讲解:
在请求回调里将请求返回的值进行一个赋值操作,如果我们的后台不规范,当数据为空的时候,给前端返回了一个null,而不是一个空数组。而且此时可以看到我们在代码中其实是用到了这个值进行了一个判断渲染,null上面怎么会有length属性呢。
所以不妨看一看后台接口返回的是个什么鬼。
<sn-container left="74.3" top="4.25" :show="Boolean(annunciator.data.length)">
<sn-figure width="1" height="1" :data="yujingredicon.data" :background="true"> </sn-figure>
</sn-container>
components.annunciator = {
api: {
url: api + `/warning/info/listNewestMsg`,
polling: true,
interval: 33,
callback: function (ctx, data) {
ctx.annunciator.data = data;
}
},
data: []
};
推荐阅读
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
[VUE ERROR] Error in render: "TypeError: Cannot create property 'header' on boolean 'true'"
-
微信小程序报Cannot read property 'setData' of undefined的错误
-
webpack报错Cannot read property 'presetToOptions' of undefined
-
Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
Cannot read property 'tap' of undefined
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#