多个状态选中一个状态

  //<!-- 如果需要在自定义列模板中获取当前遍历项数据,那么就在 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 @ 2021-01-31 12:30  嘿!那个姑娘  阅读(174)  评论(0编辑  收藏  举报