getClientTime () {
const date = new Date()
const weeks = [ '天', '一', '二', '三', '四', '五', '六']
const that = this
this.date = {
yyyy: date.getFullYear(),
mm: date.getMonth() + 1,
dd: date.getDate(),
hh: date.getHours(),
MM: date.getMinutes(),
ss: date.getSeconds(),
week: weeks[ date.getDay() ]
}
if (this.date.mm < 10) {
this.date.mm = '0' + this.date.mm
}
if (this.date.dd < 10) {
this.date.dd = '0' + this.date.dd
}
if (this.date.hh < 10) {
this.date.hh = '0' + this.date.hh
}
if (this.date.MM < 10) {
this.date.MM = '0' + this.date.MM
}
if (this.date.ss < 10) {
this.date.ss = '0' + this.date.ss
}
setTimeout(() => {
that.getClientTime()
}, 1000)
},
```
应在created函数中调用
```js
//页面调用
<div class="fs-28">{{ date.hh + ':'+ date.MM + ':'+ date.ss }}</div>
<div class="fs-14">{{ date.yyyy + '-'+ date.mm + '-'+ date.dd }}</div>
<div class="left fs-18 lh-42">星期{{ date.week }}</div>
vue页面显示实时时间
最新推荐文章于 2024-06-17 15:58:06 发布