Ant Design Vue 修改表格头部样式

在网上搜了好多修改表格头部样式的,最后自己摸索出来,分享给大家,最后附上完整代码。
首先用到的是customHeaderRow这个API,类型是一个函数
在这里插入图片描述

1.HTML部分

<a-table 
size='small' // 样式大小
:columns="columns" 
:data-source="data" 
bordered 
:pagination="false"  // 不显示页数
:customHeaderRow="customRow" // 设置头部行属性
>
</a-table>

2.js部分

customRow(column) {
      console.log(conlumn); // 在这里可以在控制台看到有一个className ,如下图
      column.forEach((e, index) => { 
      column[index].className = 'tableClass' // 给数组中的每一列加上一个类名
      })
    },

此图是console.log(conlumn);打印出来的 可以看到每一列都有一个className
此图为conlumn打印出来的
在这里插入图片描述

3.css部分

/deep/.tableClass {
  background: #cccccc !important;
}

4.完整代码

<template>
<a-table 
size="small"
:columns="columns" 
:data-source="data" 
bordered 
:pagination="false"  // 不显示页数
:customHeaderRow="customRow" // 设置头部行属性
>
</a-table>
</template>
<script>
export default {
methods:{
  customRow(column) {
      console.log(conlumn);
      column.forEach((e, index) => {
        column[index].className = 'tableClass'
      })
    },
}
}
</script>

<style lang="less" scoped>
/deep/.tableClass {
  background: #cccccc !important;
}
</style>
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值