进度条 Progress
展示操作或任务的当前进度,比如上传文件。
基础用法
Progress 组件设置 percent
属性即可,表示进度条对应的百分比,必填,必须在 0-100。
0%
进度70
<template>
<div style="width: 350px">
<div class="mb-16">
<b-progress :percent="0"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="70" status="text" active><span>进度70</span></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="100" status="success"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="50" status="exception"></b-progress>
</div>
</div>
</template>
<template>
<div style="width: 350px">
<div class="mb-16">
<b-progress :percent="0"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="70" status="text" active><span>进度70</span></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="100" status="success"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="50" status="exception"></b-progress>
</div>
</div>
</template>
文字内显示
可以设置 text-inside
来配置文字内显示模式
<template>
<div style="width: 350px">
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="0"></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="70"></b-progress>
</div>
<div class="mb-16">
<b-progress
text-inside
:stroke-width="20"
:percent="80"
color="rgba(142, 113, 199, 0.7)"
></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="100" status="success"></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="50" status="exception"></b-progress>
</div>
</div>
</template>
<template>
<div style="width: 350px">
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="0"></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="70"></b-progress>
</div>
<div class="mb-16">
<b-progress
text-inside
:stroke-width="20"
:percent="80"
color="rgba(142, 113, 199, 0.7)"
></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="100" status="success"></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="50" status="exception"></b-progress>
</div>
</div>
</template>
设置样式
可以设置 color
和 radius
等 来配置属性样式、通过开启active可以开启动画样式
40%
30%
进度60
<template>
<div style="width: 350px">
<div class="mb-16">
<b-progress :percent="70" :show-text="false"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="40" color="#76eeff"></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="60" color="#df52ff"></b-progress>
</div>
<div class="mb-16">
<b-progress :stroke-width="20" :percent="30" color="#ffcf2f"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="60" status="text" active><span>进度60</span></b-progress>
</div>
</div>
</template>
<template>
<div style="width: 350px">
<div class="mb-16">
<b-progress :percent="70" :show-text="false"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="40" color="#76eeff"></b-progress>
</div>
<div class="mb-16">
<b-progress text-inside :stroke-width="20" :percent="60" color="#df52ff"></b-progress>
</div>
<div class="mb-16">
<b-progress :stroke-width="20" :percent="30" color="#ffcf2f"></b-progress>
</div>
<div class="mb-16">
<b-progress :percent="60" status="text" active><span>进度60</span></b-progress>
</div>
</div>
</template>
动态进度
可以配合外部操作进度
10%
<template>
<div style="width: 350px">
<b-progress :stroke-width="20" :percent="percent" active color="#ff86d8"></b-progress>
<div class="mt-16">
<b-button-group>
<b-button icon="minus" size="mini" @click="minus"></b-button>
<b-button icon="plus" size="mini" @click="add"></b-button>
</b-button-group>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const percent = ref(10)
function add() {
percent.value += 10
if (percent.value >= 100) percent.value = 100
}
function minus() {
percent.value -= 10
if (percent.value < 0) percent.value = 0
}
</script>
<template>
<div style="width: 350px">
<b-progress :stroke-width="20" :percent="percent" active color="#ff86d8"></b-progress>
<div class="mt-16">
<b-button-group>
<b-button icon="minus" size="mini" @click="minus"></b-button>
<b-button icon="plus" size="mini" @click="add"></b-button>
</b-button-group>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const percent = ref(10)
function add() {
percent.value += 10
if (percent.value >= 100) percent.value = 100
}
function minus() {
percent.value -= 10
if (percent.value < 0) percent.value = 0
}
</script>
Props
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
percent | 百分比 | Number | — | 0 |
status | 进度条状态 | String | text/success/exception | — |
stroke-width | 进度条的线宽,单位 px | Number | — | 8 |
text-inside | 进度条显示文字内置在进度条内 | Boolean | — | false |
show-text | 是否显示进度文字 | Boolean | — | true |
bg-color | 进度条背景颜色 | String | — | #f3f3f3 |
color | 进度条的颜色 | String | — | #2d8cf0 |
radius | 进度条的圆角 | String | — | 100px |
active | 进度条背景动画 | Boolean | — | false |