扫码关注官方订阅号
TypeError: Cannot set property 'titleList' of undefined类型错误,不能设置未定义的属性,
TypeError: Cannot set property 'titleList' of undefined
response.data是一个对象数组我已经初始化了titleList,不知为何说他未定义,求大神解答
this 指向更改了 你可以打印出this来看一下指向谁
解决方案
1.用箭头函数吧 2.保存this (let _this = this)
.then(res => { this.titleList = res; })
this.axios.get('XX') .then(function (response) { response=response.body; this.titleList=response.data; }) .catch(function (error) { console.log(error); })
这样试下。如果不行,把错误贴出看下!
this指针丢失,可以使用箭头函数,也可以用一个变量保存this let _this = this
let _this = this
axios.get('***').then((res) => { this.titleList=res.data; });
使用这种方式试试
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
this 指向更改了 你可以打印出this来看一下指向谁
解决方案
1.用箭头函数吧
2.保存this (let _this = this)
这样试下。如果不行,把错误贴出看下!
this指针丢失,可以使用箭头函数,也可以用一个变量保存this
let _this = this使用这种方式试试