// 时间过滤器
Vue.filter('dateFormat', function(originVal) {
const dt = new Date(originVal)
const year = dt.getFullYear()
// 不足两位用0在前面补齐
const month = (dt.getMonth() + 1 + '').padStart(2, '0')
const day = (dt.getDate() + '').padStart(2, '0')
const hour = (dt.getHours() + '').padStart(2, '0')
const minute = (dt.getMinutes() + '').padStart(2, '0')
const second = (dt.getSeconds() + '').padStart(2, '0')
return `${year}-${month}-${day} ${hour}:${minute}:${second}`
})
<!-- table表格区域 -->
<el-table :data="goodslist" border stripe>
<el-table-column type="index" label="编号" width="50"></el-table-column>
<el-table-column label="商品名称" prop="goods_name"></el-table-column>
<el-table-column label="商品价格(元)" prop="goods_price" width="95"></el-table-column>
<el-table-column label="商品重量" prop="goods_weight" width="70"></el-table-column>
<el-table-column label="创建时间" prop="add_time" width="180">
<template slot-scope="scope">
{{scope.row.add_time | dateFormat}}
</template>
</el-table-column>
<el-table-column label="操作" width="200">
<template>
<el-button type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
<el-button type="danger" icon="el-icon-delete" size="mini">删除</el-button>
</template>
</el-table-column>
</el-table>
通过作用域插槽定义过滤器
<el-table-column label="创建时间" prop="add_time" width="180">
<template slot-scope="scope">
{{scope.row.add_time | dateFormat}}
</template>
</el-table-column>