vue 进度条 组件使用演示
vue项目中需要一个进度条占比效果,将实现方法记录下来,留待复用。
2023年03月31日遇到了复用的机会,不过感觉单调了一些,所以在之前的基础上增加了一个动画效果。vue 占比动画进度条实例效
更多进度条效果实例
<template>
<div class="centerpr">
<div class="centerprs">
<p :style="{background:item.bg,width:item.percentage+'%'}"
v-for="(item,index) in list2"
:key="index">
<span :class="'label'+index">{{ item.label }}</span>
<span :class="'percentage'+index">{{ item.percentage }}%</span>
</p>
</div>
</div>
</template>
<script>
export default {
name: "jindu",
components: {},
props: {
id: {
type: String,
default() {
return '';
}
}
},
data() {
return {
list: [
{label: '已处置', value: 75, bg: 'rgba(13, 250, 238, 1)'},
{label: '未处置', value: 25, bg: 'rgba(1, 125, 255, 1)'},
],
}
},
watch: {},
computed: {
list2: function () {
let total = 0
var list2 = this.list;
var list = []
this.list.forEach((type) => {
total = total + type.value
});
list2.forEach((type) => {
var data = {
value: type.value,
percentage: Number((type.value / total) * 100).toFixed(0),
label: type.label,
bg: type.bg,
}
list.push(data)
});
return list
}
},
mounted() {
},
methods: {}
}
</script>
<style lang="scss" scoped>
.centerprs {
width: calc(100% - 40px);
margin: auto;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
position: relative;
}
.centerpr {
background-size: 100% 100%;
width: calc(100% - 100px);
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
p {
color: #fff;
font-size: 14px;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
height: 10px;
}
.label0 {
position: absolute;
left: -60px;
font-size: 16px;
font-family: PingFang;
font-weight: 500;
color: #BEC6DA;
}
.percentage0 {
left: 0;
top: -20px;
font-size: 20px;
font-family: DIN;
font-weight: bold;
color: #0DFAEE;
position: absolute;
}
.percentage1 {
right: 0;
top: -20px;
font-size: 20px;
font-family: DIN;
font-weight: bold;
color: rgba(1, 125, 255, 1);
position: absolute;
}
.label1 {
position: absolute;
right: -60px;
font-size: 16px;
font-family: PingFang;
font-weight: 500;
color: #BEC6DA;
}
p:first-child {
border-radius: 5px 0 0 5px;
}
p:last-child {
border-radius: 0 5px 5px 0;
}
}
</style>