定时器以及销毁
利用hook监听钩子函数 进行销毁 这种一般倒销毁倒计时用的比较多
hook还可以监听组件的钩子函数
mounted () {
this.timer = setInterval(() => {
this.getMyDate()
}, 1000);
this.$on('hook:destroyed', () => { clearInterval(this.timer); });
},
// mounted () {
// this.timer = setInterval(() => {this.getMyDate();}, 1000);
// },
// destroyed () {
// clearInterval(this.timer);
// },
methods: {
getMyDate () {
var _this = this;
let yy = new Date().getFullYear();
let mm = new Date().getMonth() + 1;
let dd = new Date().getDate();
// let week = new Date().getDay();
let week = '星期' + '日一二三四五六'.charAt(new Date().getDay());
let hh = new Date().getHours();
let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
_this.gettime = yy + '/' + mm + '/' + dd + ' ' + week + ' ' + hh + ':' + mf + ':' + ss;
}

浙公网安备 33010602011771号