具体效果
参数看props注解
<template>
<div class="progress-container" :style="progressStyle">
<div :style="fillStyle" class="fill">
<span v-if="showValue">{{`${value}${unit}`}}</span>
</div>
</div>
</template>
<script>
export default {
props: {
height: { //进度条高度
type: Number,
default: 25
},
isRadius: { //是否为圆角
type: Boolean,
default: true
},
progressColor: { //进度条背景色
type: String,
default: '#F1F1F1'
},
fillColor: { //进度条颜色
type: String,
default: '#008AFE'
},
valueAlign: { //数组对齐方式 left/center/right
type: String,
default: 'center'
},
value: { //进度条值
type: Number,
default: 50
},
radius: { //圆角弧度
type: Number,
default: 2
},
unit: { //数值单位
type: String,
default: '%'
},
showValue: { //是否显示数值
type: Boolean,
default: true
}
},
computed: {
progressStyle() {
return {
background: this.progressColor,
borderRadius: this.isRadius ? '4px' : 'none'
}
},
fillStyle() {
return {
background: this.fillColor,
width: `${this.value > 100 ? 100 : this.value}%`,
height: `${this.height}px`,
borderRadius: this.isRadius ? `${this.radius}px` : 'none',
lineHeight: `${this.height}px`,
textAlign: this.valueAlign,
fontSize: `${this.height * 0.5}px`
}
}
}
}
</script>
<style scoped>
.fill {
transition: all 0.5s;
/* overflow: hidden; */
color: #fff;
text-shadow: 1px 1px 1px #333;
cursor: pointer;
padding-right: 10px;
box-sizing: border-box;
}
.fill:hover {
filter: saturate(2.5);
}
</style>