效果图:

1. 我们可以给要循环的盒子动态绑定class名 并且传入一个数组
<div class="AllPeople" v-for="(item , index) in rankingData" :key="index" :class="sstt[index]">
<div class="inner">
<span class="innerContent">TOP1告警区域 {{item.area}}</span>
</div>
</div>
后台请求的数据:
ranking(){
this.$http.get('/api/warning/getTopThree').then((res)=>{
if(res.data.status === 200){
console.log(res.data.data)
this.rankingData = res.data.data
}
})
},

2. 在data中定义这个数组
sstt: [
"high",
"Medium",
"low"
],
3. 在style中分别设置样式就可以了
.Medium {
background-color: #75b9e6;
}
.low {
background-color: #71d398;
}

本文介绍如何在Vue中使用v-for指令结合动态绑定class,根据后台请求的告警等级数据(如high、medium、low)来设置盒子背景色。通过定义不同的样式类(如Medium和low),实现数据可视化的颜色展示。示例代码展示了从API获取数据、在data中定义样式数组,以及在style中定义对应样式的操作过程。
1487

被折叠的 条评论
为什么被折叠?



