美文网首页
时间定时显示

时间定时显示

作者: 懒懒猫 | 来源:发表于2022-08-02 14:50 被阅读0次
    FSW91ZN2B}O3I24TY$(WFRW.png

    需求:左侧定时器,每隔一秒动一下,右侧显示星期几

    created () {
        this.initDateTime()
        this.timer = setInterval(this.initTime(), 1000)
      },
     methods: {
        initDateTime () {
          const current = moment()
          const date = current.format('YYYY年MM月DD日 星期d')
          const week = date.slice(-1)
          let txt = ''
          if (week === '1') {
            txt = '一'
          } else if (week === '2') {
            txt = '二'
          } else if (week === '3') {
            txt = '三'
          } else if (week === '4') {
            txt = '四'
          } else if (week === '5') {
            txt = '五'
          }
          this.date = date.slice(0, date.length - 1) + txt
        },
        initTime () {
          const current = moment()
          this.time = current.format('HH:mm:ss')
          return this.initTime
        }
      },
      beforeDestroy () {
        clearInterval(this.timer)
      }
    

    相关文章

      网友评论

          本文标题:时间定时显示

          本文链接:https://www.haomeiwen.com/subject/lgoswrtx.html