【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 复制代码
在这里插入代码片
相关推荐
To_OC7 小时前
LC 128 最长连续序列:别上来就排序,O (n) 解法才是这题的灵魂
javascript·算法·leetcode
IT_陈寒11 小时前
Vue这个坑我跳了两次,原来问题出在这
前端·人工智能·后端
kyriewen11 小时前
我用 50 行代码重写了 React Router 核心,终于搞懂了前端路由原理
前端·javascript·react.js
WebInfra12 小时前
Rspack 2.1 发布:React Compiler 提速 10 倍!
前端
李明卫杭州12 小时前
CSS 媒体查询详解:一文掌握响应式设计的核心技术
前端
lichenyang45313 小时前
从 H5 按钮到 OpenHarmony 能力调用:我如何理解 ASCF 的运行链路
前端
下家13 小时前
我放弃了 Vue/React,选择自研框架
前端·前端框架
Asize14 小时前
HTML5 Canvas 基础:从按帧动画到 ECharts 数据可视化
前端·javascript·canvas
默_笙14 小时前
🎄 后端给我一堆扁平数据,我 10 行代码把它变成了树
前端·javascript
Mahut14 小时前
我用 Electron + FFmpeg 做了一个本地视频处理工作站 ClipForge
前端·ffmpeg·electron