我现在有赢组件,是从数据库中取得数据,并通过state状态存放
callGetMvnDataPackageLogFn(orderCodeData).then((res) => {
this.setState({ data: res.data });
});
我现在想要给这个添加一个计时器去定时请求数据,我自己使用的是:
const intervals = stInterval(function(){
callGetMvnDataPackageLogFn(orderCodeData).then((res) => {
this.setState({ data: res.data });
});
},200)
但是这并不行,请问该如何写?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
React官网首页的定时器例子,自己琢磨下!
计时器要在
componentDidMount生命周期方法挂上,然后在componentWillUnmount生命周期方法清除。下面是ES6(Class)的语法范例:
这个范例是参考自: https://codepen.io/cmymikechu...