时间定时显示
2022-08-02 本文已影响0人
懒懒猫
FSW91ZN2B}O3I24TY$(WFRW.png
需求:左侧定时器,每隔一秒动一下,右侧显示星期几
created () {
this.initDateTime()
this.timer = setInterval(this.initTime(), 1000)
},
methods: {
initDateTime () {
const current = moment()
const date = current.format('YYYY年MM月DD日 星期d')
const week = date.slice(-1)
let txt = ''
if (week === '1') {
txt = '一'
} else if (week === '2') {
txt = '二'
} else if (week === '3') {
txt = '三'
} else if (week === '4') {
txt = '四'
} else if (week === '5') {
txt = '五'
}
this.date = date.slice(0, date.length - 1) + txt
},
initTime () {
const current = moment()
this.time = current.format('HH:mm:ss')
return this.initTime
}
},
beforeDestroy () {
clearInterval(this.timer)
}