Newer
Older
CloudBrainNew / src / components / clock / Clock.vue
StephanieGitHub on 4 Feb 2021 1 KB first commit
<!--
 * @Description: 显示时间组件,该组件已固定宽度和字体
 * @Author: 王晓颖
 * @Date: 2020-08-08
 -->
<template>
  <div class="topTime">
    <a class="gradient-text">{{year}}</a>年<a class="gradient-text">{{mouth}}</a>月<a class="gradient-text">{{day}}</a>日
    <a class="gradient-text">{{time}}</a>
    <span>{{week}}</span>
  </div>
</template>

<script>
import moment from 'moment'
moment.locale('zh-cn')
export default {
  name: 'Clock',
  data () {
    return {
      currentTime: null, // 定时器
      year: '0000', // 年
      mouth: '00', // 月
      day: '00', // 日
      time: '00:00:00', // 时间
      week: '星期一' // 星期
    }
  },
  created () {
    // 定时刷新时间
    this.currentTime = setInterval(() => {
      this.year = moment().format('YYYY')
      this.mouth = moment().format('MM')
      this.day = moment().format('DD')
      this.time = moment().format('hh:mm:ss')
      this.week = moment().format('dddd')
    }, 1000)
  },
  destroyed () {
    clearInterval(this.currentTime)
    this.currentTime = null
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  @import '../../assets/css/variable.scss';
  // 整体白色字
  .topTime{
    color: #fff;
    font-size: .12rem;
    margin-left: .05rem;
    width: 2.2rem;
    letter-spacing: .005rem;
    font-family: $digitalFamily;
    padding-left: .1rem;
  }
  .topTime a{
    font-weight: bolder;
    font-family: $digitalFamily;
  }
  .topTime a{
    font-size: .155rem;
  }
  .topTime span{
    font-size: .12rem;
  }
</style>