vue-cli项目中将时间戳的日期格式转换成年月日(时分秒)

记得angular js中时间戳转化成正常日期格式,只要使用filter属性

{{time|'YYYY-MM-DD HH:mm:ss'}}就可以了,本以为vue也可以,试验了然而并不好用;

所以在网上找了方案,需要使用时间转换的插件moment。解决步骤如下:

在node环境下

一、npm install moment --save

二、main.js

import moment from 'moment/moment'
Vue.filter('moment', function (value, formatString) {
    formatString = formatString || 'YYYY-MM-DD HH:mm:ss';
return moment(value).format(formatString);

});

三、在需要转换日期格式的vue页面中

{{time|moment}}

解决!


你可能感兴趣的:(vue-cli项目中将时间戳的日期格式转换成年月日(时分秒))