vue element 表格根据后台返回的数据来决定展示数据还是可操作的按钮

这个其实也就是一个v-if就能搞定的事情,很简单的!看下面的代码吧,我在代码打上注释,看了就会了!

<el-table-column label="角色"min-width="100">
    <template scope="scope">
        <!--假设类型的字段是type-->
        <!--如果当前行type字段等于0,就显示超级管理员,等于2就显示管理员,以此类推-->
        <span v-if='scope.row.type===0'>超级管理员</span>
        <span v-if='scope.row.type===1'>管理员</span>
        <span v-if='scope.row.type===2'>会员</span>
        <span v-if='scope.row.type===3'>普通用户</span>
    </template>
</el-table-column>
<el-table-column label="操作" min-width="200">
    <template scope="scope">
        <!--v-if判断,根据当前行的角色类型,显示按钮-->
        <!--如果角色是超级管理员,就显示删除按钮-->
        <el-button type="primary" size="small"
                   @click="deleteDo(scope.row)" v-if="scope.row.type===0">删除
        </el-button>
        <!--如果角色是管理员或者超级管理员,就显示编辑按钮-->
        <el-button type="primary" size="small"
                   @click="editDo(scope.row)" v-if="scope.row.type===0||scope.row.type===1">编辑
        </el-button>
        <!--如果角色是普通用户,就显示文字-->
        <p v-if="scope.row.type===3">您是普通用户</p>
    </template>
</el-table-column>

猜你喜欢

转载自blog.csdn.net/Weidong32768/article/details/80596529