自定义表头有两种方式:一种是使用renderheader 一种是通过设置 Scoped slot自定义表头

一、renderheader方式

场景:给表头设置自定义按钮点击时候 批量下载或做其他事件
在这里插入图片描述

当前的那列设置 :renderheader

          <el-table-column align="center" :render-header="(h, obj) => renderHeader(h, obj, '你的参数')" width="155">
            <template slot-scope="scope">
              
            </template>
          </el-table-column&gt;

methods设置事件

    // 自定义表头
    renderHeader (h, { column, $index }, type) {
      console.log('列表加载就会触发', h, { column, $index }, type)
      let that = this
      // 逻辑h() 括号包裹标签 第一个参数是标签名 第二个属性  第三个是标签内容  如果是多个标签需要包裹数组
      return h(
        'div', [
        // 列名
        h('span', column.label),
        // 按钮
        h('el-button', {
          props: {
            type: 'primary',
            size: 'small',
          },
          style: 'color:#fff;',
          // class: "{ active: showSelectMore }",
          // class: 'className',
          on: {
          	// 各种事件触发
            click: function () {
              that.clickButton(type)
            }
          }
        }, '批量下载保单发票')
      ],
      )


    },
    // 按钮点击事件
    clickButton (type) {
      console.log('我点击了' + type + '的列')
      // this.downLoad()
    },

二、Scoped slot 方式

element-ui自定义表头链接

注意:el-table-column需要去掉labelprop属性 然后使用插槽 slot这里是引用
在这里插入图片描述

三、实例多选

在这里插入图片描述

        <el-table-column width="120"&gt;
          <template slot="header" slot-scope="scope">
            <!-- 必须有这个scope 否则多选框渲染 -->
            <span>退回保费凭证</span>
            <el-checkbox v-model="allCheckFlag" @change="changeAllsect($event)"></el-checkbox>
          </template>

          <template slot-scope="scope">
              <span style="display: inline-block;float: right;margin-top:15px;">
                <el-checkbox v-model="scope.row.selectUploadFlag" @change="changeSelect"></el-checkbox>
              </span>
          </template>
        </el-table-column>







    changeAllsect (event) {
      console.log(event)
      this.$nextTick(() => {
        this.allCheckFlag = event
      })
      if (this.allCheckFlag) {
        this.tableData2.forEach(ele => {
          ele.selectUploadFlag = true
        })
      } else {
        this.tableData2.forEach(ele => {
          ele.selectUploadFlag = false
        })
      }
    },
    changeSelect () {
      let flag = false
      this.tableData2.forEach(ele => {
        if (ele.selectUploadFlag) {
          flag = true
        }
      })

      // 当没有一个选中时候 清空最上方选中
      if (flag == false) {
        this.allCheckFlag = false
      }
    },

原文地址:https://blog.csdn.net/i_am_a_div/article/details/126885629

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_40416.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注