问题描述
我正在学习 React,现在我正在尝试使用 map 执行 get 请求和列表,但是当我运行此代码时,他们会遇到此错误Unhandled Rejection (TypeError): this.state.features.map不是函数".我已经搜索过这个,但我不明白发生了什么.
I'm learning React and now I'm trying to do a get request and list with map but when I run this code they come up with this error "Unhandled Rejection (TypeError): this.state.features.map is not a function". I have already searched this but I do not understand what is going on.
推荐答案
在你的componentWillMount中,这样做:
In your componentWillMount, just do this:
您从 API 获得的响应是一个对象,该对象具有 features
键,该键是您想要的数据对象的数组.
The response you get from the API is an object which has a key of features
which is an array of objects of the data you want.
这篇关于ReactJS“未处理的拒绝(TypeError):this.state.features.map 不是函数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!