el-progress实现进度条颜色不同
实现效果:
实现代码如下:
<template>
<div>
<h1>进度条排名</h1>
<div style="width: 400px; height: 40px; margin: 0 auto; display: flex; align-item: center; justify-content: flex-start" v-for="(item, index) in egList" :key="index">
<div style="width: 15%; line-height: 40px; text-algin: center; padding-left:10px">{{ index+1 }}</div>
<div style="width: 65%; text-algin: left; font-size: 8px;">
<!-- 名称 -->
<div style="height: 20px;">{{item.name}}</div>
<el-progress :percentage="item.num/1000*100" :show-text="false" :stroke-width="8" :color="getColor(index)"></el-progress>
</div>
<div style="width: 20%; line-height: 40px; padding-right: 10px; min-width: 40px">{{Number(item.num).toFixed(2)}}</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
egList: [
{
num: 889,
name: '小龙虾'
},
{
num: 785,
name: '车厘子'
},
{
num: 686,
name: '榴莲'
},
{
num: 535,
name: '海参'
},
{
num: 423,
name: '鲍鱼'
},
{
num: 400,
name: '炒鱿鱼'
},
{
num: 388,
name: '小洋房'
},
{
num: 376,
name: '庄园'
}
]
}
},
mounted() {},
methods: {
// 针对排名前三的颜色特殊处理
getColor(val) {
switch(val) {
case 0:
return '#ad2410';
// break;
case 1:
return '#e67845';
// break;
case 2:
return '#3d6aff';
// break;
default:
'#2f53c9';
break;
}
}
}
}
</script>
default:
'#2f53c9';
break;
}
}
}
}
</script>