vue中moment.js的用法

目录

1.安装 

2.引入


使用moment格式化日期_DeedWang的博客-CSDN博客_moment.format

Moment.js常见用法总结 - 简书


1.安装 

npm install moment

2.引入

import moment from 'moment';

 mounted () {
    this.year = moment().format('YYYY/MM/DD');
    this.time = moment().format('HH:mm:ss');
    console.log("time", this.time)
    let num = moment().format('e')
    switch (num) {
      case '1':
        this.week = '星期一'
        break
      case '2':
        this.week = '星期二'
        break
      case '3':
        this.week = '星期三'
        break
      case '4':
        this.week = '星期四'
        break
      case '5':
        this.week = '星期五'
        break
      case '6':
        this.week = '星期六'
        break
      case '0':
        this.week = '星期日'
        break
    }
    setInterval(() => {
      this.time = moment().format('HH:mm:ss');
    }, 1000)

  },

html部分:

 

     

{{time}}

     

               

{{year}}

               

{{week}}

       

 

你可能感兴趣的:(学习,vue.js)