【el-table 表头自定义全选列】

具体效果

javascript 复制代码
<el-table-column
            align="center"
            width="100px"
            :render-header="(h) =>renderHeader(h,'列名')"
          >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row['列名']"
                @change="(value) =>updatePlanStatus(scope.row,'列名',scope.$index,value)"
              />
            </template>
          </el-table-column>
javascript 复制代码
renderHeader(h, name) {
      return h("div", [
        h("el-checkbox", {
          style: "margin-right:5px",
          // 普通的 HTML 属性
          attrs: {
            id: "check1"
          },
          on: {
            change: value => {
              if (this.selectPoints.length > 0) {
                this.$nextTick(() => {
                // selectPoints 是选中的列
                  this.selectPoints.forEach((item, key) => {
                    item[name] = value;
                    // 判断数组下标
                    const index = this.pointsList.findIndex(
                      point => item.cabinNo == point.cabinNo
                    );
                    // 更新表格数据
                    this.$set(this.pointsList, index, { ...item });
                    // 上一句执行后所有选中的列都会被清除,需要重新选中
                    this.$refs.pointTable.toggleRowSelection(
                      this.pointsList[index],
                      true
                    );
                  });
                });
              }
            }
          }
        }),
        h("span", name)
      ]);
    },
javascript 复制代码
在这里插入代码片
相关推荐
前端李易安36 分钟前
Web常见的攻击方式及防御方法
前端
PythonFun1 小时前
Python技巧:如何避免数据输入类型错误
前端·python
hakesashou1 小时前
python交互式命令时如何清除
java·前端·python
天涯学馆1 小时前
Next.js与NextAuth:身份验证实践
前端·javascript·next.js
HEX9CF1 小时前
【CTF Web】Pikachu xss之href输出 Writeup(GET请求+反射型XSS+javascript:伪协议绕过)
开发语言·前端·javascript·安全·网络安全·ecmascript·xss
ConardLi1 小时前
Chrome:新的滚动捕捉事件助你实现更丝滑的动画效果!
前端·javascript·浏览器
ConardLi2 小时前
安全赋值运算符,新的 JavaScript 提案让你告别 trycatch !
前端·javascript
凌云行者2 小时前
使用rust写一个Web服务器——单线程版本
服务器·前端·rust
华农第一蒟蒻2 小时前
Java中JWT(JSON Web Token)的运用
java·前端·spring boot·json·token
积水成江2 小时前
关于Generator,async 和 await的介绍
前端·javascript·vue.js