当前位置: 首页 > news >正文

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>

效果:

http://www.lryc.cn/news/518240.html

相关文章:

  • window.print()预览时表格显示不全
  • React Router底层核心原理详解
  • linux MySQL 实时性能监控工具
  • ModuleNotFoundError: No module named ‘setuptools_rust‘ 解决方案
  • 基于Spring Boot的海滨体育馆管理系统的设计与实现
  • 【机器视觉】OpenCV 图像轮廓(查找/绘制轮廓、轮廓面积/周长、多边形逼近与凸包、外接矩形)
  • 深入浅出:React 前端框架解析与应用
  • 【网络安全设备系列】7、流量监控设备
  • qemu解析qcow文件
  • 免费网站源码下载指南:如何安全获取并降低开发成本
  • 【Ubuntu】如何设置 Ubuntu 自动每日更新:轻松保持系统安全
  • 江科大STM32入门——UART通信笔记总结
  • github gitbook写书
  • 探秘MetaGPT:革新软件开发的多智能体框架(22/30)
  • 【优选算法】Binary-Blade:二分查找的算法刃(下)
  • Improving Language Understanding by Generative Pre-Training GPT-1详细讲解
  • 分治算法——优选算法
  • EtherCAT转Modbus网关与TwinCAT3的连接及配置详述
  • Apache Hadoop YARN框架概述
  • 三甲医院等级评审八维数据分析应用(八)--数据治理的持续改进与反馈机制篇
  • XML通过HTTP POST 请求发送到指定的 API 地址,进行数据回传
  • 科大讯飞前端面试题及参考答案 (下)
  • 【理论】测试框架体系TDD、BDD、ATDD、DDT介绍
  • 如何进行全脑思维(左脑,右脑,全脑)
  • 领域驱动设计 2
  • 十年后LabVIEW编程知识是否会过时?
  • ARM交叉编译Boost库
  • uniapp:钉钉小程序需要录音权限及调用录音
  • Swin Transformer模型详解(附pytorch实现)
  • gitee 使用教程