- 执行耗时接口,页面显示计时器
let tt = document.querySelector('.spanTimer') as HTMLElement;
let num = 0;
tt.innerText = num + '秒';
let min = '';
let sec = '';
let timeOut = setInterval(function () {//开启定时器
num++;
if (num <= 60) {
tt.innerText = num + '秒';
} else {
min = (num / 60).toString().split('.')[0] + '分';
sec = num % 60 + '秒';
tt.innerText = min + sec;
}
}, 1000);
//执行成功后清除
clearInterval(timeOut);
标签:tt,查询,耗时,num,let,页面
From: https://www.cnblogs.com/anjun-xy/p/17537486.html