关于elementUI的table组件展示不同颜色的背景色

<el-table :data="dataArray" border="true" stripe="true" :cell-class-name="cellStyle">

<el-table-column align="center" prop="cityName" label="城市名称" width="100"></el-table-column>

<template v-for="(item,index) in secondArrayLength">

<el-table-column

align="center"

style="background:red"

:prop="dataArray.cityData"

:label="item"

:key="index"

width="60"

>

<template slot-scope="scope">{{scope.row.cityData[0].parameterData[index].value}}</template>

</el-table-column>

</template>

</el-table>

返回数据如下:

  "data": [

        {

            "cityName": "济南",

            "cityCode": "370100",

            "cityData": [

                {

                    "parameterId": "10000",

                    "parameterName": "烷烃(全VOCs)",

                    "parameterColor": [   

                       { level: "3", value: 113 },

                      { level: "4", value: 152 },               

                    ],                   

                }

            ]

        },

根据level设置不同颜色,

cellStyle({ row, column, rowIndex, columnIndex }) {

//把每一行的索引放进row

if (columnIndex == 0) {

return;

}

// console.log(row);

let level = row.cityData[0].parameterData[columnIndex - 1].level;

return "colorcal" + level;

}

css如下:

<style>

.colorcal1 {

background: #4bdb57 !important;

color: #ffffff;

}

.colorcal2 {

background: #eccd00 !important;

}

.colorcal3 {

background: #ff7e00 !important;

color: #ffffff;

}

.colorcal4 {

background: #e63c1b !important;

color: #ffffff;

}

.colorcal5 {

background: #b60064 !important;

color: #ffffff;

}

.colorcal6 {

background: #7e0123 !important;

color: #ffffff;

}

</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值