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
  }
}
相关推荐
董世昌414 小时前
前端跨域问题:原理、8 种解决方案与实战避坑指南
开发语言·前端·javascript
还是大剑师兰特4 小时前
markdown文件在vue网页上正确显示的方法(marked + DOMPurify)
vue.js·markdown·大剑师
铅笔侠_小龙虾4 小时前
Java 模拟实现 Vue
java·开发语言·vue.js
吃炸鸡的前端4 小时前
Vite创建react项目
前端·react.js·前端框架
IT_陈寒4 小时前
Redis性能提升40%!我用这5个冷门但高效的配置优化了千万级QPS应用
前端·人工智能·后端
晚霞的不甘4 小时前
实战精研:构建高安全、多模态的 Flutter + OpenHarmony 智慧医疗健康应用(符合 HIPAA 与医疗器械软件规范)
javascript·安全·flutter
雨季6664 小时前
Flutter 智慧金融零售服务平台:跨端协同升级金融便民体验
开发语言·javascript·ecmascript
GISer_Jing4 小时前
SSE Conf 大会分享——AI Native 3D开发革命,让创意不再被技术门槛阻挡(推荐!!!)
前端·人工智能·3d·信息可视化
一只小羊啊4 小时前
Vue + Android WebView 实现大文件 PDF 预览完整解决方案
android·vue.js·pdf·webview
克喵的水银蛇4 小时前
Flutter 通用网络图片封装实战:带占位 / 错误 / 缓存的 CachedImageWidget
开发语言·前端·javascript