我想在一段流逝的时间上打印。这是函数
public updateClock() {
let now = new Date();
this.time = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
setInterval(this.updateClock, 1000);
}我在构造函数上使用了这个函数。我的问题是: HTML页面上的时间没有变化,但我希望时间持续变化。
附注:Time是我在组件开头声明的变量,这是HTML代码:
<p>{{time}}</p>发布于 2018-06-06 10:42:47
使用setInterval函数时使用Lambda函数。
constructor(){
setInterval(() => this.updateClock(), 1000);
}
public updateClock() {
let now = new Date();
this.time = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
}发布于 2018-06-06 10:39:08
试试这个密码-
public updateClock() {
setInterval(() => {
let now = new Date();
this.time = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
}, 1000);
}
}https://stackoverflow.com/questions/50718226
复制相似问题