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显示时分秒,并实时更新时间
所有评论(0)