1.使用npm命令安装moment
npm install moment --save
2.在main.js文件里引用moment
import echarts from 'echarts'
//5.x 引用方式为按需引用
//希望使用5.x版本的话,需要在package.json中更新版本号,并切换引用方式
//import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false;
import Moment from 'moment'
// 定义全局时间戳过滤器
Vue.filter('formatDate', function(value) {
return Moment(value).format('YYYY-MM-DD HH:mm:ss')
})
new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app');
3.组件使用
<div class="wx_date"> {{item.newsTime|formatDate}} </div>
原文链接:https://blog.csdn.net/fu983531588/article/details/89330929