每秒动态更新时间
currentTime: '',
created() {
//时间每秒更新
let time = setInterval(this.getCurTime,1e3);
this.$once('hook:beforeDestroy', () => {clearInterval(time)});
}
methods:{
getCurTime(){
let date = new Date();
let Y = date.getFullYear() + '/';
let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
let HH = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
let MM = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
let SS = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
this.curTime = Y + M + D +"-"+ HH + ':' + MM + ':' + SS;
// return Y + M + D +"-"+ HH + ':' + MM + ':' + SS;
},
}