相关疑难解决方法(0)

React - 用户定义的JSX组件不呈现

我一直在尝试进行AJAX调用,然后在检索完后将其添加到我的视图中.

当前代码没有发生任何事情.

const View = () => (
    <div>
     <h1>Reports</h1>
   <statisticsPage />
    </div>
);
export default View;


var statisticsPage = React.createClass({
  getInitialState: function() {
     return {info: "loading ... "};
  },
  componentDidMount: function() {
     this.requestStatistics(1);
  },
  render: function() {
    return (
        <div>info: {this.state.info}</div>
    );
  },
  requestStatistics:function(){
      axios.get('api/2/statistics')
      .then(res => {
        values = res['data']
        this.setState({info:1})
        console.log('works!!')
      });

    }

  })
Run Code Online (Sandbox Code Playgroud)

javascript jsx reactjs

3
推荐指数
1
解决办法
1062
查看次数

标签 统计

javascript ×1

jsx ×1

reactjs ×1