<template>
<div>
<div class="appBody">
<div class="headBody">
//电子时钟
<p class="time">{{nowTime}}</p>
</div>
<div class="maxBody">
<router-view style="padding-top: 5.4167vw"></router-view>
</div>
</div>
</div>
</template>
<script>
export default {
data () {
return {
nowTime :'',
};
},
created () {
this.getNowTime()
},
mounted() {
},
methods: {
getNowTime () {
let speed = 1000
let that = this
let theNowTime = function () {
that.nowTime = that.timeNumber()
}
setInterval(theNowTime, speed)
},
timeNumber () {
let today = new Date()
let date = today.getFullYear() + '-' + this.twoDigits(today.getMonth() + 1) + '-' + this.twoDigits(today.getDate())
let time = this.twoDigits(today.getHours()) + ':' + this.twoDigits(today.getMinutes()) + ':' + this.twoDigits(today.getSeconds())
return date + ' ' + time
},
twoDigits (val) {
if (val < 10) return '0' + val
return val
},
},
}
</script>
关于如何在vue项目中引入电子时钟
最新推荐文章于 2024-07-19 12:32:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)