Vue+Element UI 向Table组建中的每一行添加一个switch组件,实现每一行单独控制

最近在做公司的设备管理系统,权限管理中有一个需求需要展示如下:

每一行表格中的switch单独控制一行;

实现效果的代码如下:

<el-table  :data="userRights" stripe border align="center"  style="width: 100%;">
              <el-table-column prop="id" label="权限编号" align="center" width="80">
              </el-table-column>
              <el-table-column prop="name" label="权限名称" align="center" width="180">
              </el-table-column>
              <el-table-column prop="describe" align="center" label="权限描述">
              </el-table-column>
              <el-table-column property="status" align="center" label="权限状态">
                <template slot-scope="scope">
                  <el-switch active-color="#13ce66" inactive-color="#ff4949" v-model="scope.row.status" @change=change(scope.$index,scope.row)>
                  </el-switch>
                </template>
              </el-table-column>
            </el-table>

备注:在第一次使用时,我将slot-scope="scope"写成 scope="scope"运行起来之后没有报错,但是会有warning警告;提示信息如下:

(Emitted value instead of an instance of Error) the "scope" attribute for scoped slots have been deprecated and replaced by "slot-scope" since 2.5. The n

ot-scope" attribute can also be used on plain elements in addition to <template> to denote scoped slots.

检查下列表组件,slot 里的 <template> 上面有个 scope 属性,改成 slot-scope

<template scope="scope">

改成

<template slot-scope="scope">

查找问题的原因是:

scope用于表示一个作为带作用域的插槽的 <template> 元素,它在 2.5.0+ 中被 slot-scope 替代。

除了 scope 只可以用于 <template> 元素,其它和 slot-scope 都相同。

猜你喜欢

转载自blog.csdn.net/qq_41725450/article/details/82661585