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
  }
}
相关推荐
山东点狮信息科技有限公司11 小时前
企业级开源OA系统推荐
vue.js·spring boot·性能优化·系统架构·开源
易知微EasyV数据可视化11 小时前
定制化3D组件开发:打造差异化孪生体验
前端·人工智能·经验分享·数字孪生
多加点辣也没关系11 小时前
JavaScript|第24章:事件循环与并发模型
开发语言·javascript·ecmascript
前端炒粉12 小时前
Vue2 SSE 流式对话完整前端代码
前端·sse·流式输出
BIM云平台开发12 小时前
【App.vue里跟踪页面跳转和用户ID】
开发语言·前端·javascript
汪汪大队u12 小时前
Zabbix 6.0 部署踩坑记:从启动失败到 Web 成功访问
前端·zabbix
顺颂时绥_112 小时前
new Set 过滤数据实战
前端
赵大仁12 小时前
Next.js + Vercel AI SDK 实战:30 分钟搭出流式 Chat 页面
前端·ai·实战·react·next.js·vercel
云空13 小时前
《Three.js 完整版3D魔方:带贴纸+中心固定+自动求解复原》
前端·javascript·3d·three.js
酸梅果茶13 小时前
【7】lightning_lm项目-LIO 前端 -IVox 局部地图
前端·slam