使用
<el-table-column label="长度(m)" align="center" prop="length" width="128">
<template slot-scope="scope">
<span>{{ scope.row.length | keepNumber }}</span>
</template>
</el-table-column>
注意,filters: 是单独的。不存放在methods:里
filters: {
keepNumber(value) { //过滤器保留4为小数
const numM = Number(value).toFixed(5);
if (numM === "NaN") {
return "0.0000";
}
const realVal = numM.substring(0, numM.length - 1);
return realVal;
},
},