首页 前端知识 elementplus el-table 修改指定列背景色

elementplus el-table 修改指定列背景色

2025-03-19 11:03:42 前端知识 前端哥 289 257 我要收藏

实现效果:

1.通过el-table的 header-cell-style、cell-style 设置指定列背景色

 <el-table
      :header-cell-style="headerCellStyle"
      :cell-style="cellStyle"
    >
      <el-table-column type="selection" width="40" fixed />
      <el-table-column type="index" label="序号" width="60" fixed />
      <el-table-column prop="subUsersID" label="用户ID" show-overflow-tooltip />
      <el-table-column prop="subUsersName" label="账号" show-overflow-tooltip />
      <el-table-column
        prop="subUsersTrueName"
        label="昵称"
        show-overflow-tooltip
      />
      <el-table-column prop="remark" label="描述" show-overflow-tooltip />
    </el-table>

2. 表头样式通过 property 判断,单元格样式通过 columnIndex 下标设置。

<script setup>

...

const headerCellStyle = (data) => {
  if (
    data.column.property == "subUsersName"
  ) {
    return { "background-color": "#A6DB8B !important" };
  }
};

const cellStyle = (data) => {
  if (data.columnIndex == 3) {
    return { "background-color": "#A6DB8B !important" };
  }
};

</script>

转载请注明出处或者链接地址:https://www.qianduange.cn//article/24104.html
标签
评论
发布的文章

动态规划感悟1

2025-03-20 12:03:52

华为NAS真实测评!

2025-03-20 12:03:52

Java设计模式之代理模式

2025-03-20 12:03:51

Linux 锁、线程同步

2025-03-20 12:03:48

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!