在el-table组件中,字段值的转换有多种实现方式:
1.使用template标签加{{}}表达式使用js方法对字段值进行转换。
2.直接使用el-table-column组件中的:formatter属性使用js方法对值进行转换。
示例代码
<el-table-column label="货物状态" align="left" prop="status" width="80px">
<template slot-scope="scope">
<span>{{ changeStatusValue(scope.row.status, statusOptions) }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" :formatter="parseStatus"/>
methods: {
changeStatusValue(index, enums) {
for (var i = 0; i < enums.length; i++) {
if (enums[i].value === index) {
return enums[i].label;
}
}
},
parseStatus(row) {
return row.status == 1 ? '有效' : row.status == 2 ? '无效' : '';
}
}