小编İsm*_*ĞLU的帖子

Axios使用Reactjs每60秒自动刷新一次

我使用ReactJS作为一个JavaScript库,我在获取数据componentDidMount()使用axios。这些接收到的数据必须每60秒重新获取一次。什么是最有效,最有效的方法?

componentDidMount() {
  const newGteeChartSeries = [];
  const newGteeChartCategories = [];
  const newmultiSelectOption = [];

  axios.get(`http://www.xxxxxxx:xxxx/api/groupdata`).then(res => {
    this.state.gteeChartSeries.map(() => {
      const data = [];

      res.data.map((item, index) => {
        data.push(item.gtee);
        newGteeChartCategories.push(item.isyeri);
        newmultiSelectOption.push({ id: item.id, isyeri: item.isyeri });
      });
      newGteeChartSeries.push({ name: "GTEE", data });
    });

    this.setState({
      teeTableData: res.data,
      gteeChartSeries: newGteeChartSeries,
      multiSelectOptions: newmultiSelectOption,
      gteeChartoptions: {
        ...this.state.options,
        xaxis: {
          categories: newGteeChartCategories
        }
      }
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

reactjs axios

5
推荐指数
1
解决办法
773
查看次数

标签 统计

axios ×1

reactjs ×1