使用场景:
当el-table列表中包含时间格式的数据时,进行格式化;
影响:
格式为“yyyy-MM-dd”;
脚步:
绑定列上的属性
其中就是格式化操作的逻辑; 只需过滤掉需要格式化的列的 props
dateFormat(row, column) {
if (column.property === 'releaseTime' || column.property === 'trainingStarttime' || column.property === 'trainingEndtime') {
// 返回格式化的列
return row[column.property].substring(0,10)
}else{
// 返回不需要惊醒格式化列源
return row[column.property]
}
},
另一种情况:
如果表中使用了slots,则上述方法不起作用;
解决方法:使用过滤器进行格式化
代码片:
filters: {
dateFormat(val) {
// 返回不需要惊醒格式化列源
return val.substring(0,10)
}
},