Vue.js:实时显示当前时间

Vue.js实时显示当前时间:

在<template>里添加

<div>{{date}}</div>
在<script>里添加
复制代码
export default {
  data () {    
      date: new Date(new Date().getTime() + 8*3600*1000).toJSON().substr(0, 19).replace('T', ' ')
  },
  mounted() {
    let _this = this;
    this.timer = setInterval(() => {
      _this.date = new Date(new Date().getTime() + 8*3600*1000).toJSON().substr(0, 19).replace('T', ' ')
    }, 1000)
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  }
}
复制代码

效果:

 

posted @   新*  阅读(706)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)

喜欢请打赏

扫描二维码打赏

支付宝打赏

点击右上角即可分享
微信分享提示