多个状态选中一个状态

  //<!-- 如果需要在自定义列模板中获取当前遍历项数据,那么就在 template 上声明 slot-scope="scope" -->
<el-table-column
          label="状态">
          <template slot-scope="scope">
            <el-tag :type="articleStatus[scope.row.status].type">{{ articleStatus[scope.row.status].text }}</el-tag>
          </template>
        </el-table-column>
//这是另一种方式
            //<!-- <el-tag v-if="scope.row.status === 0" type="warning">草稿</el-tag>
            //<el-tag v--elseif="scope.row.status === 1">待审核</el-tag>
            //<el-tag v-else-if="scope.row.status === 2" type="success">审核通过</el-tag>
            //<el-tag v-else-if="scope.row.status === 3" type="danger">审核失败</el-tag>
            // <el-tag v-else-if="scope.row.status === 4" type="info">已删除</el-tag> -->
articleStatus: [
        { status: 0, text: '草稿', type: 'info' }, // 0
        { status: 1, text: '待审核', type: '' }, // 1
        { status: 2, text: '审核通过', type: 'success' }, // 2
        { status: 3, text: '审核失败', type: 'warning' }, // 3
        { status: 4, text: '已删除', type: 'danger' } // 4
      ],

通过slot-scope="scope"可以获取到 row, column, $index 和 store(table 内部的状态管理)的数据,用法参考 demo
可获得当前遍历的数据。取出当前遍历的status,与定义的articleStatus比较,得出当前应该显示的状态

posted @   嘿!那个姑娘  阅读(177)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示