Skip to content

进度条 Progress


展示操作的当前进度

何时使用

  • 当需要显示当前进度和状态时
  • 当需要显示一个操作完成的百分比时

基本使用

60%

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

const percent = ref(60)
</script>
<template>
  <Progress :percent="percent" />
</template>

完成进度条

Show Code
vue
<template>
  <Progress width="100%" :percent="100" />
</template>

渐变进度条

strokeColor: { '0%': '#108ee9', '100%': '#87d068', direction: 'right' } 或 { from: '#108ee9', to: '#87d068', direction: 'right' }


60%

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

const percent = ref(60)
</script>
<template>
  <Progress
  :percent="percent"
  :strokeColor="{
    '0%': '#108ee9',
    '100%': '#87d068',
    direction: 'right'
  }" />
</template>

进度圈

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

const percent = ref(60)
function onIncrease (scale: number) {
  const res = percent.value + scale
  if (res > 100) {
    percent.value = 100
  } else {
    percent.value = res
  }
}
function onDecline (scale: number) {
  const res = percent.value - scale
  if (res < 0) {
    percent.value = 0
  } else {
    percent.value = res
  }
}
</script>
<template>
  <Space align="center" :size="30">
    <Progress
      type="circle"
      :width="120"
      :percent="percent" />
    <Button @click="onDecline(5)" size="large">Decline-</Button>
    <Button @click="onIncrease(5)" size="large">Increase+</Button>
  </Space>
</template>

自定义文字格式

60 Days

60%

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

const percent = ref(60)
</script>
<template>
  <Space align="center" :size="30">
    <Progress
      type="circle"
      :width="160"
      :stroke-width="10"
      :percent="percent"
      :format="(percent: number) => `${percent} Days`" />
    <Progress
      type="circle"
      :width="160"
      :stroke-width="10"
      :percent="100"
      :format="() => 'Done'" />
    <Progress type="circle" :width="160" :stroke-width="10" :percent="percent">
      <template #format="{ percent }">
        <span style="color: magenta">{{ percent }}%</span>
      </template>
    </Progress>
  </Space>
</template>

APIs

参数说明类型默认值必传
width进度条总宽度number | string'100%'false
percent当前进度百分比number0false
strokeColor进度条的色彩,传入 string 时为纯色,传入 Gradient 时为渐变string | Gradient'#1677FF'false
strokeWidth进度条线的宽度,单位pxnumber8false
showInfo是否显示进度数值或状态图标booleantruefalse
format内容的模板函数Function | slot(percent: number) => percent + '%'false
type进度条类型'line' | 'circle''line'false

Gradient Type

名称说明类型必传
'0%'起始值stringfalse
'100%'终点值stringfalse
from起始值stringfalse
to终点值stringfalse
direction渐变方向'right' | 'left'false

Released under the MIT License.