在main.js里设置时间过滤器。
Vue.filter('dateFormat',(val)=>{
const dt = new Date(val)
const y = dt.getFullYear()
const m = (dt.getMonth() + 1 + '').padStart(2, '0')
const d = (dt.getDate() + '').padStart(2, '0')
const hh = (dt.getHours() + '').padStart(2, '0')
const mm = (dt.getMinutes() + '').padStart(2, '0')
const ss = (dt.getSeconds() + '').padStart(2, '0')
//时间格式年月日、时分秒
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
在列中应用这个过滤器名称
<el-table-column prop="createTime" label="创建日期">
<template slot-scope="scope">
{{scope.row.createTime | dateFormat}}
</template>
</el-table-column>