- 在main.js里import
import util from '@/assets/js/util.js'
- 在main.js全局注册 ,用Vue.filter(“过滤器名字”,“内容”)注意要在vue实例之前
//自定义过滤器过滤时间 作用:将1415674835697的时间戳转为 yyyy/MM/dd hh:mm:ss 格式时间
Vue.filter("timeForm",function(time){
time =(typeof time=='string')?parseInt(time) : time
let date=new Date(time)
return util.formatDate(date,'yyyy/MM/dd hh:mm:ss');
});
- 用管道这种在table里使用(借助插槽)
<el-table-column prop="createDate" label="创建时间">
<template slot-scope="scope">
{{scope.row.createDate|timeForm}}
</template>
</el-table-column>