你可以使用 el-table 的 slot-scope 属性来自定义单元格的内容,并使用 v-bind:class 来控制特定字符的背景颜色。

首先,在 el-table-column 中添加一个 slot-scope 属性:

<el-table-column prop="name" label="姓名" width="120">
  <template slot-scope="scope">
    <div :class="{'highlight': scope.row.name.includes('特定字符')}">{{ scope.row.name }}</div>
  </template>
</el-table-column>

然后,在你的样式表中定义 highlight 类的样式:

.highlight {
  background-color: yellow;
}

这样,当单元格的内容包含特定字符时,该单元格的背景颜色将变为黄色。

el-table中单元格的内容 对特定字符添加黄色背景

原文地址: https://www.cveoy.top/t/topic/iyr5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录