我基本上想每 X 分钟进行一次备份,但为了简单起见,我们假设我只想控制台记录某些内容或执行一些异步操作。它应该在后台运行,并且不会阻止我的应用程序的其余部分。有什么建议吗?
最佳答案
您可以在componentDidMount
中使用setInterval
,并且可以将1000
更改为变量。
componentDidMount() {
this.interval = setInterval(() => console.log("here"), 1000 );
}
componentWillUnmount() {
clearInterval(this.interval);
}
关于javascript - 如何在应用程序后台每 X 秒记录一次控制台日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57084015/