<div>标准时间为:{{ timer }}</div>
<script>
export default {
data() {
return {
timer:null, // 定时器名称
}
},
mounted(){ // 在挂载生命周期 设置定时器
this.timer = setInterval(() => {
this.timer = new Date();
},1000)
},
beforeDestroy(){ // 在销毁之前前生命周期 消除定时器
clearInterval(this.timer)
this.timer = null
},
}
</script>