天天看点

Vue使用时间过滤器

进行全局定义过滤器

npm install moment -S

第一步、在main.js中

import moment from ‘moment/moment’

定义全局时间过滤器

Vue.filter(‘moment’,function(value,formatString){

formatString = formatStrng || ‘YYYY-MM-DD HH:mm:ss’;

return moment().format(formatString);

})

第二步、在页面中使用

{{ datetime | moment }}