如何刷新自动反应js页面

时间:2020-05-12 21:04:26

标签: javascript reactjs refresh render page-refresh

我在react页面上遇到问题。我会自动刷新我的反应页面

我应该怎么做?任何人都可以帮助。.

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);
}

我也想刷新组件数据。

请帮帮我吗?

0 个答案:

没有答案