我想在页面中使用计时器,每三秒像服务器请求一次数据并更新表格,我一开始是在页面中使用,但是发现this.setState只能设置页面的数据而不能单独去设置Table的数据,于是我新建了一个文件夹然后在组件里修改(我使用的TableBasic)但是组件里没有setState。
·
var dataSource = [];
class Result extends React.Component{
constructor(props) {
super(props);
// Don't call this.setState() here!
this.state = { data: dataSource };
//this.handleClick = this.handleClick.bind(this);
}
componentDidMount(){
/this.timerID = setInterval(()=>{
console.log("Fetch result...")
request('http://localhost:8081/api/result/').then(data=>{
//console.log(data);
dataSource.push(data);
//console.log(dataSource);
this.setState({
dataSource: dataSource
})
})
}, 3000);/
}
`
编译器报错:
Property 'timerID' does not exist on type 'VideoResult'.ts(2339)
我重新编译了下,这回虽然编译器报错,但是运行的时候没有报错,但是我目前仍然无法做到每隔3秒让表格组件自己重新渲染。
https://protable.ant.design/example#%E8%BD%AE%E8%AF%A2
Most helpful comment
https://protable.ant.design/example#%E8%BD%AE%E8%AF%A2