当前位置: 首页 > news >正文

Element UI表格中根据数值动态设置字体颜色

我们有一个温度监控系统,需要展示温度偏差值:

  • 正偏差值(高于标准温度)显示为红色

  • 负偏差值(低于标准温度)显示为蓝色

  • 零或空值显示为默认颜色

一、动态Class绑定

<el-table-column sortable="custom" prop="deviationValue" label="偏差值(℃)" width="75"><template #default="scope"><div class="openParamsClass over-emplis" :class="getDeviationClass(scope.row.deviationValue)"@click="chartOpen(scope.row.id, 'deviationValue', '偏差值')" :title="scope.row.deviationValue">{{ scope.row.deviationValue != null ? scope.row.deviationValue : '-' }}</div></template>
</el-table-column>

css

.deviation-positive {color: #ff4d4f;font-weight: 500;
}.deviation-negative {color: #1890ff;font-weight: 500;
}.deviation-zero {color: #606266;
}

二、动态Style绑定

<el-table-column sortable="custom" prop="deviationValue" label="偏差值(℃)" width="75"><template #default="scope"><div class="openParamsClass over-emplis" :style="getDeviationStyle(scope.row.deviationValue)"@click="chartOpen(scope.row.id, 'deviationValue', '偏差值')" :title="scope.row.deviationValue">{{ scope.row.deviationValue != null ? scope.row.deviationValue : '-' }}</div></template>
</el-table-column>

方法:

methods: {getDeviationStyle(value) {if (value === null || value === undefined || value === '-') {return { color: '#606266' };}const numValue = Number(value);if (numValue > 0) {return { color: '#ff4d4f', fontWeight: '500' };} else if (numValue < 0) {return { color: '#1890ff', fontWeight: '500' };} else {return { color: '#606266' };}}
}

三、模板内联判断

<el-table-column sortable="custom" prop="deviationValue" label="偏差值(℃)" width="75"><template #default="scope"><div class="openParamsClass over-emplis" :style="{color: scope.row.deviationValue > 0 ? '#ff4d4f' : scope.row.deviationValue < 0 ? '#1890ff' : '#606266',fontWeight: scope.row.deviationValue !== 0 ? '500' : 'normal'}"@click="chartOpen(scope.row.id, 'deviationValue', '偏差值')" :title="scope.row.deviationValue">{{ scope.row.deviationValue != null ? scope.row.deviationValue : '-' }}</div></template>
</el-table-column>

http://www.dtcms.com/a/460795.html

相关文章:

  • AI量化投资决策Agent系列-比尔·阿克曼Agent
  • C 标准库 - `<limits.h>》
  • 51c大模型~合集190
  • # **DRF Response 对象**
  • 临夏建设网站易烊千玺网页设计模板代码
  • 自己开发网站要多少钱如何快速找到做网站的客户
  • zookeeper:一致性原理和算法
  • 如何设置时钟服务器时间
  • Shell 编程
  • 来料不良---供应商还是企业的问题?
  • 六轴工业机器人可视化模拟平台 (Vue + Three.js + Blender)
  • Java数据结构:单链表
  • 硬件基础深度解析(一):电阻——电路世界中无处不在的基石**
  • 记力扣2106.摘水果 练习理解
  • Java中的泛型 Generics
  • [linux仓库]信号产生[进程信号·贰]
  • 网站内部链接优化网红营销李佳琦案例分析
  • 有哪些网站设计比较好的公司wordpress右上角登录
  • 在Python中加载.pkl文件
  • HarmonyOS大厂面试总结大全二
  • python 字符串压缩(字符串-中等)含源码(九)
  • 如何自己设计一个网页宁波seo推广哪家好
  • 【STM32项目开源】STM32单片机智能温室大棚控制系统
  • 车牌 OCR 识别:国庆高速免费通行的 “隐形引擎”
  • wpf之TabControl
  • WPF应用最小化到系统托盘
  • 使用平行型子环腔的 23 KHz 线宽 1064 nm SOA 光纤激光器
  • 保定企业建站程序wordpress数据都被存在哪
  • 深圳做网站做app少儿戏曲知识 网站建设
  • SymPy 符号计算:从基础到高级的完整指南