在 Element UI Table 的官网上,有一个“筛选”功能,里面可以利用 slot-scope,给表格记录打标签。
关键代码为:
<template slot-scope="scope">
<el-tag
:type="scope.row.tag === '家' ? 'primary' : 'success'"
disable-transitions>{{scope.row.tag}}</el-tag>
</template>
利用三元表达式为 <el-tag> 标签设定样式。
条件渲染指令:
<
el-tag v-if="scope.row.state === '已完成'" :type="'success'"
disable-transitions>{{scope.row.state}}
</el-tag>
<el-tag v-else-if="scope.row.state === '未开始'" :type="'danger'"
disable-transitions>{{scope.row.state}}
</el-tag>
<el-tag v-else-if="scope.row.state === '进行中'" :type="'warning'"
disable-transitions>{{scope.row.state}}
</el-tag>
success---蓝色
danger---红色
warning---绿色