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
  }
}
相关推荐
前端互助会8 小时前
Live2D形象展示与文本语音播报:打造生动交互体验的完整实现
前端·vue.js·microsoft·交互
chilavert3189 小时前
技术演进中的开发沉思-191 JavaScript: 发展历程(上篇)
开发语言·javascript·ecmascript
努力的小郑9 小时前
今晚Cloudflare一哆嗦,我的加班计划全泡汤
前端·后端·程序员
武昌库里写JAVA10 小时前
微擎服务器配置要求,微擎云主机多少钱一年?
java·vue.js·spring boot·后端·sql
dy171710 小时前
el-table表头上下显示内容
javascript·vue.js·elementui
q***649710 小时前
头歌答案--爬虫实战
java·前端·爬虫
凌波粒10 小时前
SpringMVC基础教程(4)--Ajax/拦截器/文件上传和下载
java·前端·spring·ajax
亮子AI11 小时前
给你的应用加上Google账号登录
javascript
液态不合群11 小时前
DDD驱动低代码开发:从业务流程到领域模型的全链路设计
前端·低代码·架构·ddd
jonyleek11 小时前
JVS低代码开发中,如何创建自定义前端页面并接入到现有系统中,从创建到接入的全攻略
前端·低代码·前端框架·软件开发