欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > el-table 自定义表头颜色

el-table 自定义表头颜色

2025/2/8 12:05:36 来源:https://blog.csdn.net/2301_76162638/article/details/145000826  浏览:    关键词:el-table 自定义表头颜色

第一种方法:计算属性

<template><div><el-table:data="formData.detail"border stripehighlight-current-row:cell-style="{ 'text-align': 'center' }":header-cell-style="headerCellStyle"><el-table-column fixed prop="id" label="序号" width="80px" type="index"/><el-table-column prop="partCode" label="编码" width="120px"/><el-table-column prop="name" label="名称"/><el-table-column prop="spec" label="规格"/><el-table-column prop="partStuff" label="材质"/><el-table-column prop="partUnit" label="单位"/><el-table-column prop="batchNumber" label="批次号" /><el-table-column prop="number" label="数量" /></el-table></div></template><script>const formData = ref([])const headerCellStyle = ({ column, $index }) =>{let style = {background: '#b7babd',color: '#1e1f22',height: '35px','text-align': 'center'};if (column.property == 'batchNumber' || column.property == 'number' ) {style.background = '#e7c265';}return style;
}</script>

第二种方法:深度样式

<template><div><el-table:data="formData.detail"border stripehighlight-current-row:cell-style="{ 'text-align': 'center' }":header-cell-style="{background: '#b7babd',color: '#1e1f22',height: '35px','text-align': 'center'}"><el-table-column fixed prop="id" label="序号" width="80px" type="index"/><el-table-column prop="partCode" label="编码" width="120px"/><el-table-column prop="name" label="名称"/><el-table-column prop="spec" label="规格"/><el-table-column prop="partStuff" label="材质"/><el-table-column prop="partUnit" label="单位"/><el-table-column prop="batchNumber" label="批次号" :header-cell-class-name="'custom-header-class'"/><el-table-column prop="number" label="数量" /></el-table></div></template><script>const formData = ref([])const headerCellStyle = ({ column, $index }) =>{let style = {background: '#b7babd',color: '#1e1f22',height: '35px','text-align': 'center'};if (column.property == 'batchNumber' || column.property == 'number' ) {style.background = '#e7c265';}return style;
}</script><style scoped>/* 使用 :deep() 确保样式能穿透到子组件 */.el-table-style :deep(.custom-header-class) {background: #a1884b !important; /* 使用 !important 提高优先级 */color: #1e1f22;height: 35px;text-align: center;}
</style>

效果:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com