让el-table表头某一个单元格变色的一种方法
(认知有限,如有不妥,还望告知,欢迎讨论。)
环境:vite,vue3,element plus
目的:实现表头的这种填色效果

方法:
在el-table通过 header-cell-style判断单元格位置 更新单元格样式。
样例代码:
<template>
...
<el-table
class="table"
:data="userList.data"
:border="true"
:header-cell-style="grayColor"
stripe
>
...
</template>
<script>
...
const grayColor = ({ column }: { column: any }) => {
if (column.label === 'No.') {
return {
backgroundColor: 'gray',
color: '#ffffff',
}
} else {
return {
backgroundColor: '#409eff',
color: '#ffffff',
}
}
}
...
</script>
=END=
=Reference=
[1] https://blog.csdn.net/Akatsuki233/article/details/100311040
[2] https://juejin.cn/post/7091271859253035045
[3] https://element-plus.org/zh-CN/component/table.html