1. // 自定义创建一个过滤器
    2. // dateFormat为过滤器的名称, originVal是需要处理的时间
    3. Vue.filter("dateFormat",function(originVal) {
    4. // 通过new Date获取当前时间的对象
    5. const dt = new Date(originVal);
    6. // 获取年月日,时分秒
    7. const y = dt.getFullYear();
    8. // 月份是从0开始的,所以加1,通过padStart方法给1-9月前面添加一个0(参数一是长度,参数二是当长度不够时用什么补全)
    9. const m = (dt.getMonth() + 1 + '').padStart(2,'0');
    10. const d = (dt.getDate() + '').padStart(2,'0');
    11. const hh = (dt.getHours() + '').padStart(2,'0');
    12. const mm = (dt.getMinutes() + '').padStart(2,'0');
    13. const ss = (dt.getSeconds() + '').padStart(2,'0');
    14. // return `yyyy-mm-dd hh-mm-ss`
    15. return `${y}-${m}-${d} ${hh}-${mm}-${ss}`;
    16. })
    1. <el-table-column
    2. prop="add_time"
    3. label="创建时间">
    4. <template slot-scope="scope">
    5. <!-- 通过插槽获取当前列的数据,通过以下过滤器将数据格式修改 -->
    6. {{scope.row.add_time | dateFormat}}
    7. </template>
    8. </el-table-column>