Vue.js报错—TypeError: Cannot read property 'Name' of undefined

Vue.js报错—TypeError: Cannot read property 'Name' of undefined,第1张

错误:name未定义 原因是ajax是一个异步请求在加载的

解决方法:

    因为获取信息是异步请求,所以vue绑定数据时,你的name赋值为空对象的话,获取的值就为undefined,所以会报错我们只需要

    

data()中,你定义了itemsList:[],也就是空的数组

template中,你又使用了itemsList[0],这个时候itemsList[0]=undefined,自然就报错了

注意,是先进行页面渲染再ajax异步获取数据,也就是数据还没到就会渲染一次,数据到了再渲染一次,第一次渲染你就报错了。

通常有两种情况:

1、在模板的html标签上使用length报错

vue 中使用 length判断的时候,有时会报错,如下:

解决方法:

改成: formcheckVal !== undefined && formcheckVallength > 0

或者: formcheckVal !== null && formcheckVallength > 0

2、在js中使用length报错,如下

报错原因:此时resData是无数据为undefined的,所以找不到 resDatalength。

解决办法:在加一层判断,首先保证resData存在不为null或undefined改为,如下

</article>

以上就是关于Vue.js报错—TypeError: Cannot read property 'Name' of undefined全部的内容,包括:Vue.js报错—TypeError: Cannot read property 'Name' of undefined、vue中,我从后台取出数据渲染vue组件,我数据渲染出来了,但是页面有报错,是什么原因、vue报错'length' of undefined"(如果报null则把undefined改null)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10155534.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存