首页IT科技怎么可以退出快手粉丝团成员(已解决:TypeError: Cannot read properties of undefined (reading ‘name‘ ))

怎么可以退出快手粉丝团成员(已解决:TypeError: Cannot read properties of undefined (reading ‘name‘ ))

时间2025-06-20 14:55:25分类IT科技浏览6234
导读:错误描述 TypeError: Cannot read properties of undefined (reading ‘name‘ ...

错误描述

TypeError: Cannot read properties of undefined (reading ‘name‘ )

这个错误在前端中蛮常见的              ,一般都是提示的这个属性没写对                   ,但是呢        ,如果仅仅是这么一个简单的错误           ,也没必要特意写个博客记录一下 这个错误呢                  ,最常见的解决方式就是查看他提示这个“name              ”           ,看看哪个地方写错了

解决方案

我是在对接口返回值做处理的时候遇到的        ,简单的来说                   ,就是我需要对接口返回的某个值做处理              ,如下所示:

viewResults(row.id).then(response => { console.log(response) for (var i = 1; i < response.data.list.length; i++) { if (response.data.list[i - 1].score[3] == response.data.list[i - 1].score[4]) { this.gridData[i].name = response.data.list[i - 1].name this.gridData[i].catename = response.data.list[i - 1].catename this.gridData[i].score = response.data.list[i - 1].score.substring(0, 6) } else { this.gridData[i].name = response.data.list[i - 1].name this.gridData[i].catename = response.data.list[i - 1].catename this.gridData[i].score = response.data.list[i - 1].score.substring(0, 5) } } })

具体id错误原因是这样的    ,vue给对象数组添加对象时for循环只执行一次(我在data中手中加了一个对象                    ,所以只执行了一次)                 ,这个其实就是赋值产生的问题,所以上面这么写是错的                 ,正确写法如下所示:

viewResults(row.id).then(response => { for(var i = 1;i<response.data.list.length;i++){ let obj ={}; if(response.data.list[i-1].score[3] == response.data.list[i-1].score[4]){ obj.name = response.data.list[i-1].name obj.catename = response.data.list[i-1].catename obj.score = response.data.list[i-1].score.substring(0,6) }else{ obj.name = response.data.list[i-1].name obj.catename = response.data.list[i-1].catename obj.score = response.data.list[i-1].score.substring(0,5) } this.gridData.push(obj) } })

PS:push() 方法可向数组的末尾添加一个或多个元素                    ,并返回新的长度              。新元素将添加在数组的末尾                   。此方法改变数组的长度        。

声明:本站所有文章    ,如无特殊说明或标注              ,均为本站原创发布           。任何个人或组织                   ,在未征得本站同意时        ,禁止复制             、盗用                      、采集      、发布本站内容到任何网站         、书籍等各类媒体平台                  。如若本站内容侵犯了原著者的合法权益           ,可联系我们进行处理           。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
字符串中的字符怎么表示(字符串的解读和标签模板) 怎样找到自己的价值观和价值观(怎样找到自己的价值观和行为)