使用三元表达式显示el-tag标签的不同颜色和内容
实现-在render中
1、两个颜色
代码:
{
prop: "gatewayStatus",
label: "状态",
search: { el: "select", props: { filterable: true } },
tag: true,
enum: gatewayStatus,
render: (scope: { row: Device.ResGateway }) => {
return (
<el-tag type={scope.row.gatewayStatus == 1 ? "" : "warning"}>{scope.row.gatewayStatus == 1 ? "在线" : "掉线"}</el-tag>
);
}
},
2、三个颜色
代码:
{
prop: "screenStatus",
label: "状态",
enum: screenStatus,
search: { el: "select", props: { filterable: true } },
tag: true,
render: (scope: { row: Device.ResScreen }) => {
return (
<el-tag type={scope.row.screenStatus == 1 ? "" : scope.row.screenStatus == 2 ? "success" : "warning"}>
{scope.row.screenStatus == 1 ? "在线" : scope.row.screenStatus == 2 ? "使用中" : "掉线"}
</el-tag>
);
}
},
3、四个颜色
代码:
{
prop: "patientStatus",
label: "状态",
enum: patientStatus,
search: { el: "select", props: { filterable: true } },
tag: true,
render: (scope: { row: Patient.ResPatient }) => {
return (
<el-tag
type={
scope.row.patientStatus == 0
? ""
: scope.row.patientStatus == 1
? "success"
: scope.row.patientStatus == 2
? "warning"
: "info"
}
>
{scope.row.patientStatus == 0
? "输液中"
: scope.row.patientStatus == 1
? "休息"
: scope.row.patientStatus == 2
? "待输液"
: "出院"}
</el-tag>
);