This question already has answers here:
How to perform an action every couple of seconds?
(6个答案)
在10个月前关闭。
我基本上希望每隔X分钟执行一次备份,但是为了简单起见,让我们说我只想控制台日志或执行一些异步操作。它应该在后台运行,并且不会阻止我的应用程序的其余部分。有什么建议吗?
(6个答案)
在10个月前关闭。
我基本上希望每隔X分钟执行一次备份,但是为了简单起见,让我们说我只想控制台日志或执行一些异步操作。它应该在后台运行,并且不会阻止我的应用程序的其余部分。有什么建议吗?
最佳答案
您可以在setInterval
中使用componentDidMount
,并且可以将1000
更改为变量。
componentDidMount() {
this.interval = setInterval(() => console.log("here"), 1000 );
}
componentWillUnmount() {
clearInterval(this.interval);
}
关于javascript - 如何在我的应用程序后台每隔X秒创建一个控制台日志? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57084015/
10-11 19:33