Vue使用moment格式化日期

Vue使用moment格式化日期


在平常的开发中,后端响应的日期可能不是标准的格式,我们可以用monment进行格式化
1.打开终端进行安装moment

npm install moment --save

2.在vue项目当中main.js中引用

import moment from 'moment'

3.使用全局过滤器进行日期格式化

Vue.use(require('vue-moment'));
Vue.prototype.moment = moment
Vue.filter('dateFormat',function(dateStr,pattern='YYYY-MM-DD HH:mm:ss'){
  return moment(dateStr).format(pattern);

4.具体使用:

<el-table-column
        prop="createdate"
        header-align="center"
        align="center"
        label="创建时间">
        <template slot-scope="scope">{{scope.row.createdate| dateFormat}}</template>
</el-table-column>

这样就可以将日期进行格式化
5.页面具体显示:
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章