【发布时间】:2018-04-12 00:42:01
【问题描述】:
我从响应中得到了我需要的数据,但是我得到一个 TypeError 并且我不明白为什么?我需要做什么来解决这个问题?
componentDidMount() {
const getData = axios.get("https://web-code-test-xxx-games-prd.appspot.com/cards.json")
.then(function(response) {
const easyResponse = response.data.levels[0]['difficulty']
const easyCards = response.data.levels[0]['cards']
this.setState({ easy: easyResponse})
this.setState({easyCards: easyCards})
})
.catch(function(error) {
console.log(error);
});
}
【问题讨论】:
-
错误是什么?
-
TypeError{},我四处寻找更详细的解释,但没有运气。是因为它获取一个 json 吗?
-
这是响应对象 {data: Object, status: 200, statusText: "", headers: Object, config: Object...} data: Object levels: Array[2] 0: Object 1:对象状态:200 statusText:“”标头:对象配置:对象请求:XMLHttpRequest
-
TypeError 来自我设置状态的方式
标签: javascript reactjs axios