1.下载
npm i dayjs --save
2.导入
import dayjs from "dayjs";
export default {
data() {
return {
// 初始化数据
currentTime: "",
timeOut: null,
};
},
mounted() {
// 获取当前时间
this.timeOut = setInterval(() => {
this.currentTime = dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss");
}, 1000);
},
beforeDestroy(){
clearInterval(this.timeOut);
},