let timer = setInterval(() => {
setTimeout(
function () {
getCmd();
}, 0);
}, 30000);
document.onvisibilitychange = () => { //切换页面时关闭定时器
if (document.visibilityState == "visible") {
let timer = setInterval(() => {
setTimeout(
function () {
getCmd();
}, 0);
}, 2000);
} else {
clearInterval(timer);
}
}
定时请求最新数据和离开页面销毁定时器
最新推荐文章于 2024-04-20 13:41:03 发布