【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 复制代码
在这里插入代码片
相关推荐
海石5 小时前
微信小程序开发01:XR-FRAME的快速上手
前端·增强现实·trae
叶梅树7 小时前
DocsJS npmjs 自动化发布复盘(Trusted Publisher)
前端·npm
喵叔哟8 小时前
9. 【Blazor全栈开发实战指南】--Blazor调用JavaScript
开发语言·javascript·udp
我命由我123458 小时前
Element Plus - Form 的 resetField 方法观察记录
开发语言·前端·javascript·vue.js·html·html5·js
清空mega8 小时前
《Vue3 项目结构详解:components、views、assets、router、stores 到底该怎么理解?》
前端·javascript·vue.js
雨雨雨雨雨别下啦9 小时前
Vue——小白也能学!Day6
前端·javascript·vue.js
XPoet9 小时前
AI 编程工程化:Hook——AI 每次操作前后的自动检查站
前端·后端·ai编程
難釋懷10 小时前
RedisTemplate配置读写分离
前端·bootstrap·html
冰暮流星10 小时前
javascript如何实现删除数组里面的重复元素
开发语言·前端·javascript
网络点点滴11 小时前
透传属性$attrs
前端·javascript·vue.js