el-table单元格背景色动态改变

首先在el-table加上这个 :cell-style=“tableCellStyle”

<el-table :data="turnoutList" border :height="300" :cell-style="tableCellStyle">
	<el-table-column label="设备名称" width="110px" align="center" key="devName" prop="devName" fixed
                         sortable :show-overflow-tooltip="true">
        </el-table-column>
 </el-table>

然后是js方法

<script setup>
//这里是需要动态改变背景色的单元格,键是label,值是prop
const fieldMappings = {
  '设备名称': 'devName',
  '灯光配置': 'lightNum',
};

//动态改变单元格背景色
function tableCellStyle({ row, column, rowIndex, columnIndex }) {
  const fieldLabel = column.label;
  const fieldName = fieldMappings[fieldLabel];

  if (fieldName && (row[fieldName] === undefined || row[fieldName] === '')) {
    return { 'background-color': 'red' };
  }
}
</script>

效果如下,第一行有值,第二行没值背景色为红色
在这里插入图片描述

相关推荐

  1. 双击编辑el-table单元数据

    2024-01-26 21:56:02       59 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-26 21:56:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-26 21:56:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-26 21:56:02       82 阅读
  4. Python语言-面向对象

    2024-01-26 21:56:02       91 阅读

热门阅读

  1. yum找不到 mysql-server

    2024-01-26 21:56:02       46 阅读
  2. 65.Spring 框架中都用到了哪些设计模式?

    2024-01-26 21:56:02       58 阅读
  3. 公司减资好处 公司减资条件 深圳公司减资流程

    2024-01-26 21:56:02       57 阅读
  4. Linux之buildroot

    2024-01-26 21:56:02       49 阅读
  5. Linux 下后台运行程序,查看和关闭后台运行程序

    2024-01-26 21:56:02       57 阅读
  6. C语言-算法-并查集

    2024-01-26 21:56:02       54 阅读
  7. 五、RHCE--NFS服务器

    2024-01-26 21:56:02       57 阅读
  8. 响应式编程——R2DBC

    2024-01-26 21:56:02       59 阅读
  9. 寒假实训第二天

    2024-01-26 21:56:02       59 阅读
  10. 【ChatGPT 和文心一言哪个更好用?】

    2024-01-26 21:56:02       50 阅读