如题,
其实应该把 setInterval 和 setTimeout 结合起来使用,如下面例子:
created: function() {
window.setInterval(() => {
setTimeout(this.getCurrTime(), 0);
}, 1000);
}
上面是一个实时时间显示器,每一秒调一次接口,将此刻的时间显示到页面上来。
如题,
其实应该把 setInterval 和 setTimeout 结合起来使用,如下面例子:
created: function() {
window.setInterval(() => {
setTimeout(this.getCurrTime(), 0);
}, 1000);
}
上面是一个实时时间显示器,每一秒调一次接口,将此刻的时间显示到页面上来。