Skip to content

Progress 进度条

用于展示任务完成比例,适合上传、表单步骤、异步处理进度等场景。

交互式调试

🔧调试模式Playground

基础用法

最常见的用法是传入 percentage,组件会自动将值限制在 0 ~ 100 之间。

vue
<lk-progress :percentage="50" />

状态色

当不想手动指定颜色时,可通过 status 使用内置语义色。

vue
<template>
  <lk-progress :percentage="30" />
  <lk-progress :percentage="70" status="success" />
  <lk-progress :percentage="50" status="warning" />
  <lk-progress :percentage="100" status="error" />
</template>

条纹效果

通过 striped 增加进度感,通过 animated 让条纹流动,适合“进行中”状态。

vue
<lk-progress :percentage="50" striped animated />

自定义高度与颜色

vue
<lk-progress :percentage="50" :stroke-width="24" color="#f56c6c" track-color="#fee2e2" />

文字内显

当进度条高度足够时,可将百分比文字放到条内。

vue
<lk-progress :percentage="80" :stroke-width="32" text-inside />

动态更新

percentage 是普通响应式属性,适合配合上传进度、轮询状态、按钮交互动态更新。

vue
<script setup lang="ts">
import { ref } from 'vue'

const progress = ref(20)

function increase() {
  progress.value = Math.min(progress.value + 10, 100)
}
</script>

<template>
  <lk-progress :percentage="progress" />
  <lk-button type="primary" @click="increase">继续</lk-button>
</template>

推荐示例

1) 直接复用项目 Demo(推荐)

vue
<script setup lang="ts">
import ProgressDemo from '@/components/demos/progress-demo.vue'
</script>

<template>
  <ProgressDemo />
</template>

2) 在业务页中按需组合

vue
<template>
  <view class="page-demo">
    <lk-progress />
  </view>
</template>

API

Props

参数说明类型默认值
percentage进度百分比,组件内部会限制在 0 ~ 100number0
striped是否显示条纹booleanfalse
animated条纹是否流动booleanfalse
textInside是否将文字显示在进度条内部booleanfalse
showText是否显示进度文字booleantrue
strokeWidth进度条高度,数字按 rpx 处理number12
color进度条颜色,支持纯色或渐变背景string''
trackColor轨道颜色string''
status状态色'' | success | warning | error | danger''
id根节点 idstring''
customClass根节点自定义类名string | object | array
customStyle根节点自定义样式string | object

Events

事件名说明回调参数
change进度百分比变化时触发,值已限制在 0 ~ 100(percentage, oldPercentage)
complete进度首次到达 100 时触发(percentage)

Slots

使用建议

TIP

需要品牌色或渐变色时优先使用 color;仅表达语义状态时优先使用 status,便于统一主题。

WARNING

启用 textInside 时,请同步增大 strokeWidth,否则文字区域会显得拥挤。

基于 MIT 协议开源 · 粤ICP备2022114240号-3

Progress 进度条

正在连接预览服务...

请先运行 pnpm run dev:h5