使用场景:
当el-table 的列表 中包含时间格式的数据,对其进行格式化操作;
效果:
格式化为 'yyyy-MM-dd' 形式;
操作步骤:
在列中绑定formatter 该属性
其中dateFormat是格式化操作的逻辑;过滤出需要格式化的列的prop即可
/**
* @description: 格式化日期
* @param {*} row
* @param {*} column
* @return {*}
* @author: greatwang
*/
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]
}
},
另一种场景:
如果在表格中使用了插槽,那么上述的formatter方法会不起作用;
解决方法:使用filter 过滤器进行格式化
代码片:
filters: {
/**
* @description: 格式化日期
* @param {*} val
* @return {*}
* @author: greatwang
*/
dateFormat(val) {
// 返回不需要惊醒格式化列源
return val.substring(0,10)
}
},