讓el-table表頭某一個單元格變色的一種方法
(認(rèn)知有限,如有不妥,還望告知,歡迎討論。)
環(huán)境:vite,vue3,element plus
目的:實現(xiàn)表頭的這種填色效果

方法:
在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