如何刷新Auto react js页面

问题描述 投票:0回答:1

我面临着一个问题,在反应页面。 我做自动刷新我的反应页面

我应该怎么做,有人能帮帮我吗?

import React, { Component } from 'react';

class App extends Component {

    this.state = {   
      appointmentdata:[],
   }

  //fetch appointment data
  componentDidMount() {
axios.get(`http://localhost/v1/appointments`)
.then(res => {
  console.log(res);
  const appointmentdata = res.data; 
  setInterval(() => {
    this.setState({     
      appointmentdata :appointmentdata.appointments , 
    });
  }, 1000);  //refresh my api only
})

}


componentWillUnmount() {
  console.log("will");
  clearInterval(this.interval);
}

我也想刷新我的组件数据。

请帮助我吗?

javascript reactjs refresh page-refresh
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.