vue3 自定义渲染表头及添加图标el-table render-header h函数

el-table-column 添加  :render-header="renderHeader"

import sortIcon from "./sortIcon.vue"; //表单父组件引入方式
import {h} from "vue";//引入h
//render-header="renderHeader "  renderHeader 方法
const renderHeader = ({ column }) => {
  const styleFilter= {
    'height': '9px',
    'width': '30px',
  }
  const arr = ["a",'b','c'];//哪些表头字段需要添加图标
  if (props.selectPlanYield && arr.includes(column.property)) {
    return h("div", [
      h("span", column.label),
      h("div", [
        h(sortIcon, {  //sortIcon组件名字
          onClick: handeSort,//给组件传递点击事件on +自定义名字 首字母必须大写,子组件用emits('click')触发
          property: column.property,//props传值,子组件还是props接收
          style: {
          },
        }),
      ]),
      h(filterIcon, {
        onClick: handeFiler,
        onClose: handleCancel,
          property: column.property,
        style: {
          ...styleFilter,//设置样式
        },
      }),
    ]);
  } else {
    return h("div", [h("span", column.label)]);//其他表头字段
  }
};


//sortIcon 子组件接收和触发事件

const props = defineProps({
  property: {
    type: String,
    default: "",
  },
});

const = handleClick =()=>{
emit("click");
}

表头样式如下

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值