类型错误:this.state.champions.map 不是函数

克里斯蒂安·冈萨雷斯

我通过API后端而不是前端拉数据我从我的服务器拉它我应该推动状态在一个空数组中,这样我就可以映射,但我一直得到一个

类型错误:this.state.champions.map 不是函数

import React, { Component } from "react";
import axios from "axios";
class Champions extends Component {
  constructor(props) {
    super(props);

    this.state = {
      champions: []
    };
  }

  componentWillMount() {
    axios.get("/api/Champions").then(response => {
      this.setState({ champions: response.data });
      // console.log(response);
    });
  }

  render() {
    console.log(this.state.champions);
    // let champions = this.state.champions;
    let champList = this.state.champions.map((elem, ind) => {
      return <div key={elem} className="champCard" />;
    });
    return <div className="App">{champList}</div>;
  }
}

export default Champions;

我的控制台日志

法林斯基

您在您的response.data而不是数组中收到一个对象

所以你可以把它转换成这样的英雄数组:

componentWillMount() {
  axios.get("/api/Champions").then(response => {
    this.setState({ champions: Object.values(response.data) });
  });
}

更新:

正如评论中所建议的那样 -在这种情况下最好使用componentDidMount而不是componentWillMount请阅读有关componentDidMount 的更多信息

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

类型错误:this.state.user.map 不是反应中的函数

来自分类Dev

类型错误:this.state.article.map 不是函数 REACT

来自分类Dev

类型错误:this.state.patients.map 不是函数

来自分类Dev

类型错误:this.state.userInfo.map 不是函数

来自分类Dev

反应类型错误:this.state.entries.map 不是函数

来自分类Dev

类型错误:this.state.merchentOrders.map 不是函数

来自分类Dev

ReactJS“未处理的拒绝(类型错误):this.state.features.map 不是函数”

来自分类Dev

收到错误this.state.datas.map不是函数

来自分类Dev

错误:.map()不是函数

来自分类Dev

未捕获的类型错误:this.state.pokemon.filter 不是函数?

来自分类Dev

this.state.events.map不是函数

来自分类Dev

TypeError:state.confirmed.map不是函数

来自分类Dev

TypeError:this.state.employees.map不是函数

来自分类Dev

TypeError:this.state.tasks.map不是函数

来自分类Dev

TypeError:this.state.userDtl.map不是函数

来自分类Dev

this.state.post.map不是函数

来自分类Dev

如何修复 this.state.*.map 不是函数?

来自分类Dev

反应错误:未处理的拒绝(TypeError):this.state.categories.map不是函数

来自分类Dev

类型错误:this.http.get(...).map 不是函数

来自分类Dev

ReactJs - 带有 Object.keys().map 的搜索过滤器 - 未捕获的类型错误:this.state.texts.filter 不是 t.value 的函数

来自分类Dev

遇到 this.state 不是函数错误

来自分类Dev

React JS-TypeError:this.state.data.map不是函数

来自分类Dev

反应| TypeError:this.state.cars.map不是函数

来自分类Dev

未定义不是函数(在'... this.state.results.map ...'附近)

来自分类Dev

未处理的拒绝(TypeError):this.state.personals.map不是函数

来自分类Dev

TypeError:undefined不是函数(在'... this.state.profile.map ...'附近)

来自分类Dev

ReactJS TypeError:_this3.state.Objects.map 不是函数

来自分类Dev

React Native this.state.questions.map() 不是函数

来自分类Dev

Laravel + React:this.state.tasks.map 不是函数

Related 相关文章

  1. 1

    类型错误:this.state.user.map 不是反应中的函数

  2. 2

    类型错误:this.state.article.map 不是函数 REACT

  3. 3

    类型错误:this.state.patients.map 不是函数

  4. 4

    类型错误:this.state.userInfo.map 不是函数

  5. 5

    反应类型错误:this.state.entries.map 不是函数

  6. 6

    类型错误:this.state.merchentOrders.map 不是函数

  7. 7

    ReactJS“未处理的拒绝(类型错误):this.state.features.map 不是函数”

  8. 8

    收到错误this.state.datas.map不是函数

  9. 9

    错误:.map()不是函数

  10. 10

    未捕获的类型错误:this.state.pokemon.filter 不是函数?

  11. 11

    this.state.events.map不是函数

  12. 12

    TypeError:state.confirmed.map不是函数

  13. 13

    TypeError:this.state.employees.map不是函数

  14. 14

    TypeError:this.state.tasks.map不是函数

  15. 15

    TypeError:this.state.userDtl.map不是函数

  16. 16

    this.state.post.map不是函数

  17. 17

    如何修复 this.state.*.map 不是函数?

  18. 18

    反应错误:未处理的拒绝(TypeError):this.state.categories.map不是函数

  19. 19

    类型错误:this.http.get(...).map 不是函数

  20. 20

    ReactJs - 带有 Object.keys().map 的搜索过滤器 - 未捕获的类型错误:this.state.texts.filter 不是 t.value 的函数

  21. 21

    遇到 this.state 不是函数错误

  22. 22

    React JS-TypeError:this.state.data.map不是函数

  23. 23

    反应| TypeError:this.state.cars.map不是函数

  24. 24

    未定义不是函数(在'... this.state.results.map ...'附近)

  25. 25

    未处理的拒绝(TypeError):this.state.personals.map不是函数

  26. 26

    TypeError:undefined不是函数(在'... this.state.profile.map ...'附近)

  27. 27

    ReactJS TypeError:_this3.state.Objects.map 不是函数

  28. 28

    React Native this.state.questions.map() 不是函数

  29. 29

    Laravel + React:this.state.tasks.map 不是函数

热门标签

归档