在 vueJS 2 中带有分页但无法呈现的 element-ui 表行的背景颜色

V L*_*udi 5 javascript vuejs2 element-ui

我必须根据表中的结果列为 false 添加红色背景颜色,为 true 添加绿色背景,我使用 elementUI + 数据表分页 + vuejs。我尝试通过在结果列上使用样式绑定来添加列声明,提前致谢

我的模板代码

<template slot="header" slot-scope="table" :style = "customRowBackground(table.row)">
<template slot-scope="table">{{ table.row.launch_success }}</template>
</el-table-column>
Run Code Online (Sandbox Code Playgroud)

我的 customRowBackgrond() 函数

 customRowBackgrond({row}){     
      if (row.launch_success == true) {
        return {'backgrondColor': 'rgb(252, 230, 190)'};
      } 
      else if (row.launch_success == false) {
        return { backgrondColor: 'rgb(252, 230, 190)'};
      } 
      else {
        return {backgrondColor: 'rgb(252, 230, 190)'};
      }
    },
Run Code Online (Sandbox Code Playgroud)

我需要在我的整个表中获得绿色的真实值和红色的假值......提前致谢。

Rid*_*dhi 8

尝试这个

:style = "table.row.launch_success == true ? '{"backgrondColor": "rgb(252, 230, 190)"}' : table.row.launch_success == false ? '{"backgrondColor": "rgb(252, 230, 190)"}' : '{"backgrondColor': "rgb(252, 230, 190)"}'
Run Code Online (Sandbox Code Playgroud)

或者

在模板中

<el-table :data="tableData2" style="width: 100%" :row-class-name="tableRowClassName">
Run Code Online (Sandbox Code Playgroud)

更新方法如下

methods: {
      tableRowClassName({row, rowIndex}) {
        if (row.launch_success == true) {
          return 'success-row';
        } else if (row.launch_success == false) {
          return 'warning-row';
        }
        return 'other-row';
      }
    },
Run Code Online (Sandbox Code Playgroud)

更新 CSS 如下

.el-table .warning-row {
background: 'rgb(252, 230, 190)';
}

.el-table .success-row {
background: 'rgb(252, 230, 190)';
}

.el-table .other-row {
background: 'rgb(252, 230, 190)';
}
Run Code Online (Sandbox Code Playgroud)