【发布时间】:2019-05-20 09:59:18
【问题描述】:
它显示以下错误: 未处理的拒绝(TypeError):无法读取未定义的属性“数据”
axios.get(`http://localhost:4000/api/AMS/country`)
{
.then(response => {
//In the below line I am getting the error
const country_Claim_Type = response.data;
console.log(country_Claim_Type);
this.setState({ country_Claim_Type });
})
}
我期待一些 json 数据,但我在控制台中未定义。
【问题讨论】:
-
那么当你 console.log() 输出响应时,它会显示/提供什么?
-
它只显示“未定义”。我认为数据变得空,这就是为什么它显示未定义但我不知道为什么?
-
错误信息表示未定义响应,可能是返回错误?
-
是的,它抛出了以下错误:TypeError: Cannot read property 'data' of undefined
-
我解决了这个问题,有一个愚蠢的错误,错误是我忘了把 return 放在 axios.get 之前