在template里面
<div class="dongtaitime">
<div class="bgsj">报告时间: {{nowTime}}</div>
</div>
在script里面
data() {
return {
// 动态时间定义
timer: undefined,
nowTime: new Date()
}
created() {
//时间1方法
// 要显示时间,在渲染页面之前一直调用该函数,对this.time进行赋值开启定时
this.timer = setInterval(() => {
this.nowTime = new Date().toLocaleString();
});
},
// 关闭页面销毁定时器
beforeDestroy() {
if (this.timer) {
clearInterval(this.timer);
}
},