我在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);
}
我也想刷新组件数据。
请帮帮我吗?