Skip to content

Progress 进度条

进度条(Progress)用于展示操作或任务的当前进度,帮助用户了解处理状态。

基础用法

使用 v-model 进行双向绑定,或通过 :value 传入静态值。默认 max=100

vue
<!-- 静态值 -->
<TProgress :value="75" />

<!-- 双向绑定 -->
<TProgress v-model:value="progVal" showLabel />

颜色

通过 color 属性设置进度条颜色,支持所有 Tabler 预设色。

vue
<TProgress :value="75" color="primary" />
<TProgress :value="60" color="success" />
<TProgress :value="45" color="danger" />
<TProgress :value="30" color="warning" />
<TProgress :value="90" color="info" />

显示百分比标签

开启 showLabel 属性可在进度条上显示百分比文字。

vue
<TProgress :value="68" showLabel />

条纹进度条

开启 striped 属性可为进度条添加条纹动画效果。

vue
<TProgress :value="50" striped showLabel />

不确定状态

当进度未知或持续加载时,使用 indeterminate 属性显示循环动画。

vue
<TProgress indeterminate />

尺寸

通过 sm 属性切换到小尺寸(默认高度为普通尺寸)。

vue
<TProgress :value="75" sm showLabel />
<TProgress :value="75" showLabel />

原生 progress 元素

开启 native 属性将渲染为 HTML <progress> 元素,适合需要浏览器原生进度条的场景。

vue
<TProgress :value="50" native />

多条进度

通过 <TProgress> 容器嵌套多个 <TProgressBar> 子组件,可以实现分段进度条。

vue
<TProgress>
  <TProgressBar :value="30" color="primary" />
  <TProgressBar :value="50" color="success" />
  <TProgressBar :value="10" color="danger" />
</TProgress>

TProgressBar 同样支持 stripedshowLabel 等属性。

vue
<TProgress>
  <TProgressBar :value="40" color="primary" striped showLabel />
  <TProgressBar :value="25" color="warning" />
  <TProgressBar :value="20" color="success" showLabel />
</TProgress>

程序化控制

通过 step 控制每次调用 advance() 增加的进度值,initial 控制起始位置。调用 reset() 可回到起始值。监听 @complete 事件可在进度到达 max 时做出响应。

advance()reset() 直接修改 v-model 绑定的值,无需手动处理事件。

查看代码
vue
<script setup>
const progRef = ref()
const progVal = ref(10)

function onComplete() {
  console.log('进度已达到 100%!')
}
</script>

<template>
  <TProgress ref="progRef" v-model:value="progVal" :initial="10" :step="15" showLabel @complete="onComplete" />
  <t-button @click="progRef?.advance()">前进 (+15)</t-button>
  <t-button @click="progRef?.reset()">重置</t-button>
</template>

API

TProgress 属性 (Props)

属性名说明类型默认值
v-model:value当前进度值 (0–max)number0
max最大值number100
sm是否使用小尺寸booleanfalse
color进度条颜色TablerColor'primary'
striped是否显示条纹动画booleanfalse
indeterminate是否为不确定状态(循环动画)booleanfalse
native是否渲染为原生 <progress> 元素booleanfalse
showLabel是否显示百分比标签booleanfalse
step步长,调用 advance() 时每次增加的值number10
initial起始位置,调用 reset() 时回到该值number0

TProgress 方法 (Methods)

通过模板引用 (ref) 调用。

方法名返回值说明
advance()step 步长增加进度,到达 max 时触发 @complete 事件
reset()重置进度到 initial
currentnumber响应式的当前进度值(可通过 ref 访问)

TProgress 事件 (Events)

事件名说明
@complete进度到达 max 时触发

TProgress 插槽 (Slots)

插槽名说明
default用于传入多个 <TProgressBar> 组件,实现多条进度。

TProgressBar 属性 (Props)

属性名说明类型默认值
value当前进度值 (0–max)number必填
max最大值number100
color进度条颜色TablerColor'primary'
striped是否显示条纹动画booleanfalse
indeterminate是否为不确定状态booleanfalse
showLabel是否显示百分比标签booleanfalse