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