一,在el-table-column中加入 :formatter="gridDateFormatter",其中gridDateFormatter是一个公用方法。
二,在methods或者公用的js文件中,添加该方法:
gridDateFormatter(row, column, cellValue, index) {
const daterc = row[column.property];
if (daterc) {
const dateMat = new Date(daterc);
const Y = dateMat.getFullYear() + "-";
const M =
dateMat.getMonth() + 1 < 10
? "0" + (dateMat.getMonth() + 1) + "-"
: dateMat.getMonth() + 1 + "-";
const D =
dateMat.getDate() < 10
? "0" + dateMat.getDate() + " "
: dateMat.getDate() + " ";
const H =
dateMat.getHours() < 10
? "0" + dateMat.getHours() + ":"
: dateMat.getHours() + ":";
const F =
dateMat.getMinutes() < 10
? "0" + dateMat.getMinutes() + ":"
: dateMat.getMinutes() + ":";
const S =
dateMat.getSeconds() < 10
? "0" + dateMat.getSeconds() + ":"
: dateMat.getSeconds() + "";
return Y + M + D + H + F + S;
}
},