【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 复制代码
在这里插入代码片
相关推荐
前端 贾公子几秒前
@uni-helper 社区:让 uni-app 拥抱 ESM 时代
开发语言·前端·javascript
大卡拉米1 分钟前
ClaudeCode安装及使用
前端·学习
豆豆2 分钟前
PageAdmin CMS模板开发详解:HTML转CMS系统的10个核心步骤
前端·html·cms·网站建设·网站制作·自助建站·网站管理系统
lemon_yyds2 分钟前
vue 2 升级vue3 : element ui 校验红色高亮失去效果
前端·element
真夜2 分钟前
又遇到生产与开发环境结果不一致问题。。。
前端·javascript·http
lemon_yyds2 分钟前
vue2升级vue3:图片点击预览出现样式错乱
前端
掘金安东尼2 分钟前
低代码工具很多,为什么 RollCode 更像一套「页面生产平台」
前端·javascript·面试
HelloReader2 分钟前
Flutter StatefulWidget让界面动起来(六)
前端
umigreen2 分钟前
uniapp实现小程序地图导航
前端
JYeontu2 分钟前
旅游拍的照片不要扔,一键生成炫酷的 3D 照片球动画
前端