element table 表头header-cell-style设置的表头不生效

只要加个!important就可以了,像这样。标点符合不能多写

header-cell-style是官网写的修改el-table表头样式的回调,且说header-row-style不生效也就罢了,header-cell-style也不生效是不是有点过分。

我抓耳挠腮的看了半天,最后手写了个样式进去,但还是气不过,把他改过来,最后在多次查资料(搜索)终于找到了原因,或许是表格父级元素使用了flex布局的原因,只要加个!important就可以了,像这样。

javascript 复制代码
   <el-table :data="tableData" border :style="{ width: width }" :height="height"
        :header-cell-style="tableHeaderCellStyle" 
        >
        <template v-for="(item, index) in tableHeader">
          <el-table-column v-if="item.label == '排序' || item.label == '排名'" :prop="item.prop" :label="item.label"
            :width="item.width" show-overflow-tooltip align="center">
            <template #default="scope">
              <span :style="getStyle(scope)">{{ scope.row[item.prop] }}</span>
            </template>
          </el-table-column>
          <el-table-column v-else :prop="item.prop" :label="item.label" :width="item.width" align="center"
            show-overflow-tooltip>
          </el-table-column>
        </template>
      </el-table>


// 修改 table header cell的背景色
const tableHeaderCellStyle = ({ row, column, rowIndex, columnIndex }) => {
  let background = null
 
  if (rowIndex == 0) {
    props.tableHeader.map((item, index) => {
      if (columnIndex == index && item.background) {
        background = `${item.background} !important`
      }
    })
  }
  // return  { background: 'pink !important' } // 使用 backgroundColor
  // 如果有背景色,则返回一个样式对象
  if (background) {
    return { background: background };  // 使用 backgroundColor
  }
}
相关推荐
东风破_3 小时前
React 受控组件与非受控组件:从一个输入框讲清表单数据流
前端
尤乐娃子3 小时前
进入大厂(厂子大)实习Day12
前端·笔记·实习
程序员爱钓鱼4 小时前
Rust Copy详解:隐式复制与轻量数据类型
前端·后端·rust
四六的六5 小时前
端侧模型多端部署实战:从格式转换到灰度发布,Web 和移动端统一部署流水线
前端·人工智能·大模型·ai编程·ai模型·ai产品·端侧ai
vx-程序开发7 小时前
springboot农产品运输服务平台---附源码75498
java·javascript·spring boot·python·eclipse·django·php
独隅7 小时前
前端离线暂停更新策略:Service Worker 与 PWA 的静默控制实践
前端
妙码生花8 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(五十八):后台系统配置管理实现
前端·后端·go
用户938515635078 小时前
React 受控/非受控组件与 React.memo 性能优化——从本质到实战
前端·javascript·react.js
IT_陈寒8 小时前
Java并行流把我坑惨了:原来不是线程安全的!
前端·人工智能·后端