方法一【element】:
<el-table-column label="状态"
prop="enabled"
:filters="[{ text: '启用', value: '启用' }, { text: '关闭', value: '关闭' }]"
:filter-method="filterTag"
filter-placement="bottom-end"
>
<template slot-scope="scope">
<el-tag
:type="onlineMap[scope.row.enabled] === '启用' ? 'success' : 'danger'"
disable-transitions
>{{ onlineMap[scope.row.enabled] }}</el-tag>
</template>
<!-- <template slot-scope="props">
{{ onlineMap[props.row.enabled] }}
</template> -->
</el-table-column>
onlineMap: {
true: '启用',
false: '关闭'
}
方法二:
<el-table-column align="center" label="上报状态" width="70">
<template slot-scope="scope">
<el-tag :type="scope.row.state | statusFilter">{{ scope.row.state | formatStata }}</el-tag>
</template>
</el-table-column>
filters: {
// el-tag类型转换
statusFilter(status) {
const statusMap = {
0: 'info',
1: 'success',
2: 'warning',
3: 'danger'
}
return statusMap[status]
},
// 状态显示转换
formatStata(status) {
const statusMap = {
0: '全部',
1: '正常',
2: '离线',
3: '未部署'
}
return statusMap[status]
}
},