您的位置:首页 > 产品设计 > UI/UE

使用 Element UI Table 的 slot-scope方法

2020-03-12 07:10 1876 查看

在 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>
  1. 这里首先利用 slot-scope 属性(Vue 2.6.0 已废弃)将子组件的数据(row.tag)传递给了父组件。
  2. 利用三元表达式为 <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>

运行结果:

官网只是基本用法,真正实践还是要靠积累与总结哦O(∩_∩)O哈哈~

以上就是本文的全部内容,希望对大家的学习有所帮助

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Element Table slot-scope