moment.js 处理时间格式
时间:2022-04-11 14:43
1.在mian.js引入moment
import moment from ‘moment‘ Vue.prototype.$moment = ‘moment‘
2. 在main.js 设置全局过滤器
Vue.filter(‘moment‘, function (value, formatString) {
formatString = formatString || ‘YYYY年MM月DD日‘;
// return moment(value).format(formatString); // value可以是普通日期 20170723
return moment.unix(value).format(formatString); // 这是时间戳转时间
});//标红处为格式的自定义 同样可以YYYY-MM-DD HH:MM:SS ,或者 YYYY/MM/DD
3.渲染到页面
<div>{{time | moment}}</div