moment.js在VUE中使用

1、安裝html

npm install momentnpm

2、定義時間格式化全局過濾器spa

在filters.js中 導入組件code

import moment from 'moment'

let formatDate = time =>{
    if (time = '' || !time){
        return '——'
    }else{
        var date = moment(time).format('YYYY-MM-DD HH:mm:ss');
        return date;                        
    }
}

export{formatDate}    

3、在頁面須要格式化時間的地方使用插值表達式就OK了orm

<template>
      <p class="subtitle">
          <span>發表時間:{{ newsinfo.time | dateformat}}</span>
     </p>
</template>
相關文章
相關標籤/搜索