<template>
<div>
<div class="top">
<div class="time">{{date}}</div>
</div>
</div>
</template>
<script>
import { dateFormat } from "../utils/index.js";
export default {
data() {
return {
date: `${
new Date().getFullYear()}年${ (new Date().getMonth()+1 >9 ? new Date().getMonth()+1 : new Date().getMonth()+1)}月${(new Date().getDate()>9 ? new Date().getDate() : '0' + new Date().getDate())}日
${new Date().getHours()>9 ? new Date().getHours(): '0' + new Date().getHours()}:${ new Date().getMinutes()>9 ? new Date().getMinutes(): '0' + new Date().getMinutes()}:${ new Date().getSeconds()>9 ? new Date().getSeconds(): '0' + new Date().getSeconds()
}`
};
},
mounted() {
let _this = this; // 声明一个变量指向Vue实例this,保证作用域一致
this.timer = setInterval(() => {
_this.date = dateFormat(Date.parse(_this.date), "Y年m月d日 H:i:s"); // 修改数据date
// _this.date = dateFormat(Date.parse(_this.date), "Y m-d H:i:s"); // 修改数据date
// dateFormat(Date.parse(_this.date), "Y年m月d日 H:i:s");
console.log('22')
}, 1000);
},
beforeDestroy() {
if (this.timer) {
clearInterval(this.timer); // 在Vue实例销毁前,清除我们的定时器
}
},
components: {}
};
</script>
<style lang='' scoped>
.top {
height: 25vh;
width: 30vw;
margin: 0 auto;
}
.title {
width: 100%;
height: 40%;
background-image: url("../assets/title.jpg");
}
</style>
vue中时间戳转换时间格式并实时刷新案例
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 在数据库的使用中,经常需要按指定日期来查询记录,以便于统计,而在数据库中,有很多存储的是时间戳, 也有的直接存日期...
- 最近因为项目需要,使用到了Excel表数据上传,遇到了一个让我非常头疼的问题,那就是excel表中的数据格式是日期...
- 日常开发中经常会遇到时间相关的问题,服务端返回的数据都是以时间戳的方式,那么需要将其处理转化为对应的时间格式,具体...
- 第一步:npm install -save moment 第二步:1.在main.js中引入,import mom...