npm install dayjs
import dayjs from 'dayjs'
mounted() {
	this.timeId = setInterval(() => {
	  this.time = dayjs().add(1, 'second').format('HH:mm:ss');
	}, 1000);
},
beforeDestroy() {
  //组件销毁前清楚定时器
  if (this.timeId) {
    clearInterval(this.timeId)
  }
},

参考:

VUE使用day.js显示时分秒,并实时更新时间

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐