Progress 进度条

用于展示操作进度,告知用户当前状态和预期。

直线进度条

Progress 组件设置 percentage 属性即可,表示进度条对应的百分比。 该属性必填,并且必须在 0-100 的范围内。 你可以通过设置 format 来自定义文字显示的格式。

Progress 进度条 - 图1

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress :percentage="50" />
  4. <el-progress :percentage="100" :format="format" />
  5. <el-progress :percentage="100" status="success" />
  6. <el-progress :percentage="100" status="warning" />
  7. <el-progress :percentage="50" status="exception" />
  8. </div>
  9. </template>
  10. <script lang="ts" setup>
  11. const format = (percentage) => (percentage === 100 ? 'Full' : `${percentage}%`)
  12. </script>
  13. <style scoped>
  14. .demo-progress .el-progress--line {
  15. margin-bottom: 15px;
  16. width: 350px;
  17. }
  18. </style>

进度条内显示百分比标识

百分比不占用额外控件,适用于文件上传等场景。

Progress 组件可通过 stroke-width 属性更改进度条的高度,并可通过 text-inside 属性来改变进度条内部的文字。

Progress 进度条 - 图2

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress :text-inside="true" :stroke-width="26" :percentage="70" />
  4. <el-progress
  5. :text-inside="true"
  6. :stroke-width="24"
  7. :percentage="100"
  8. status="success"
  9. />
  10. <el-progress
  11. :text-inside="true"
  12. :stroke-width="22"
  13. :percentage="80"
  14. status="warning"
  15. />
  16. <el-progress
  17. :text-inside="true"
  18. :stroke-width="20"
  19. :percentage="50"
  20. status="exception"
  21. />
  22. </div>
  23. </template>
  24. <style scoped>
  25. .demo-progress .el-progress--line {
  26. margin-bottom: 15px;
  27. width: 350px;
  28. }
  29. </style>

自定义进度条的颜色

可以通过 color 属性来设置进度条的颜色。 该属性可以接受十六进制颜色值,函数和数组。

Progress 进度条 - 图3

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress :percentage="percentage" :color="customColor" />
  4. <el-progress :percentage="percentage" :color="customColorMethod" />
  5. <el-progress :percentage="percentage" :color="customColors" />
  6. <el-progress :percentage="percentage" :color="customColors" />
  7. <div>
  8. <el-button-group>
  9. <el-button :icon="Minus" @click="decrease" />
  10. <el-button :icon="Plus" @click="increase" />
  11. </el-button-group>
  12. </div>
  13. </div>
  14. </template>
  15. <script lang="ts" setup>
  16. import { ref } from 'vue'
  17. import { Minus, Plus } from '@element-plus/icons-vue'
  18. const percentage = ref(20)
  19. const customColor = ref('#409eff')
  20. const customColors = [
  21. { color: '#f56c6c', percentage: 20 },
  22. { color: '#e6a23c', percentage: 40 },
  23. { color: '#5cb87a', percentage: 60 },
  24. { color: '#1989fa', percentage: 80 },
  25. { color: '#6f7ad3', percentage: 100 },
  26. ]
  27. const customColorMethod = (percentage: number) => {
  28. if (percentage < 30) {
  29. return '#909399'
  30. }
  31. if (percentage < 70) {
  32. return '#e6a23c'
  33. }
  34. return '#67c23a'
  35. }
  36. const increase = () => {
  37. percentage.value += 10
  38. if (percentage.value > 100) {
  39. percentage.value = 100
  40. }
  41. }
  42. const decrease = () => {
  43. percentage.value -= 10
  44. if (percentage.value < 0) {
  45. percentage.value = 0
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. .demo-progress .el-progress--line {
  51. margin-bottom: 15px;
  52. width: 350px;
  53. }
  54. </style>

环形进度条

Progress 组件可通过 type 属性来指定使用环形进度条,在环形进度条中,还可以通过 width 属性来设置其大小。

Progress 进度条 - 图4

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress type="circle" :percentage="0" />
  4. <el-progress type="circle" :percentage="25" />
  5. <el-progress type="circle" :percentage="100" status="success" />
  6. <el-progress type="circle" :percentage="70" status="warning" />
  7. <el-progress type="circle" :percentage="50" status="exception" />
  8. </div>
  9. </template>
  10. <style scoped>
  11. .demo-progress .el-progress--line {
  12. margin-bottom: 15px;
  13. width: 350px;
  14. }
  15. .demo-progress .el-progress--circle {
  16. margin-right: 15px;
  17. }
  18. </style>

仪表盘形进度条

您也可以指定 type 属性到 dashboard 使用控制面板进度栏。

Progress 进度条 - 图5

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress type="dashboard" :percentage="percentage" :color="colors" />
  4. <el-progress type="dashboard" :percentage="percentage2" :color="colors" />
  5. <div>
  6. <el-button-group>
  7. <el-button :icon="Minus" @click="decrease" />
  8. <el-button :icon="Plus" @click="increase" />
  9. </el-button-group>
  10. </div>
  11. </div>
  12. </template>
  13. <script lang="ts" setup>
  14. import { onMounted, ref } from 'vue'
  15. import { Minus, Plus } from '@element-plus/icons-vue'
  16. const percentage = ref(10)
  17. const percentage2 = ref(0)
  18. const colors = [
  19. { color: '#f56c6c', percentage: 20 },
  20. { color: '#e6a23c', percentage: 40 },
  21. { color: '#5cb87a', percentage: 60 },
  22. { color: '#1989fa', percentage: 80 },
  23. { color: '#6f7ad3', percentage: 100 },
  24. ]
  25. const increase = () => {
  26. percentage.value += 10
  27. if (percentage.value > 100) {
  28. percentage.value = 100
  29. }
  30. }
  31. const decrease = () => {
  32. percentage.value -= 10
  33. if (percentage.value < 0) {
  34. percentage.value = 0
  35. }
  36. }
  37. onMounted(() => {
  38. setInterval(() => {
  39. percentage2.value = (percentage2.value % 100) + 10
  40. }, 500)
  41. })
  42. </script>
  43. <style scoped>
  44. .demo-progress .el-progress--line {
  45. margin-bottom: 15px;
  46. width: 350px;
  47. }
  48. .demo-progress .el-progress--circle {
  49. margin-right: 15px;
  50. }
  51. </style>

自定义内容

通过默认插槽添加自定义内容。

Progress 进度条 - 图6

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress :percentage="50">
  4. <el-button text>Content</el-button>
  5. </el-progress>
  6. <el-progress
  7. :text-inside="true"
  8. :stroke-width="20"
  9. :percentage="50"
  10. status="exception"
  11. >
  12. <span>Content</span>
  13. </el-progress>
  14. <el-progress type="circle" :percentage="100" status="success">
  15. <el-button type="success" :icon="Check" circle />
  16. </el-progress>
  17. <el-progress type="dashboard" :percentage="80">
  18. <template #default="{ percentage }">
  19. <span class="percentage-value">{{ percentage }}%</span>
  20. <span class="percentage-label">Progressing</span>
  21. </template>
  22. </el-progress>
  23. </div>
  24. </template>
  25. <script lang="ts" setup>
  26. import { Check } from '@element-plus/icons-vue'
  27. </script>
  28. <style scoped>
  29. .percentage-value {
  30. display: block;
  31. margin-top: 10px;
  32. font-size: 28px;
  33. }
  34. .percentage-label {
  35. display: block;
  36. margin-top: 10px;
  37. font-size: 12px;
  38. }
  39. .demo-progress .el-progress--line {
  40. margin-bottom: 15px;
  41. width: 350px;
  42. }
  43. .demo-progress .el-progress--circle {
  44. margin-right: 15px;
  45. }
  46. </style>

动画进度条

使用 intermediate 属性来设置不确定的进度, duration 来控制动画持续时间。

Progress 进度条 - 图7

  1. <template>
  2. <div class="demo-progress">
  3. <el-progress :percentage="50" :indeterminate="true" />
  4. <el-progress :percentage="100" :format="format" :indeterminate="true" />
  5. <el-progress
  6. :percentage="100"
  7. status="success"
  8. :indeterminate="true"
  9. :duration="5"
  10. />
  11. <el-progress
  12. :percentage="100"
  13. status="warning"
  14. :indeterminate="true"
  15. :duration="1"
  16. />
  17. <el-progress :percentage="50" status="exception" :indeterminate="true" />
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. const format = (percentage) => (percentage === 100 ? 'Full' : `${percentage}%`)
  22. </script>
  23. <style scoped>
  24. .demo-progress .el-progress--line {
  25. margin-bottom: 15px;
  26. width: 350px;
  27. }
  28. </style>

Progress 属性

属性说明类型可选值默认值
percentage百分比,必填number0-1000
type进度条类型stringline/circle/dashboardline
stroke-width进度条的宽度number6
text-inside进度条显示文字内置在进度条内(仅 type 为 ‘line’ 时可用)booleanfalse
status进度条当前状态stringsuccess/exception/warning
indeterminate是否为动画进度条boolean-false
duration控制动画进度条速度number-3
color进度条背景色 进度条背景色 (会覆盖 status 状态颜色)string/function/array‘’
width环形进度条画布宽度(只在 type 为 circle 或 dashboard 时可用)number126
show-text是否显示进度条文字内容booleantrue
stroke-linecapcircle/dashboard 类型路径两端的形状stringbutt/round/squareround
format指定进度条文字内容function(percentage)

Progress 插槽

名称说明
default自定义内容,参数为 { percentage }

源代码

组件 Progress 进度条 - 图8 文档 Progress 进度条 - 图9

贡献者

Progress 进度条 - 图10 三咲智子

Progress 进度条 - 图11 云游君

Progress 进度条 - 图12 jeremywu

Progress 进度条 - 图13 류한경

Progress 进度条 - 图14 Aex

Progress 进度条 - 图15 C.Y.Kun

Progress 进度条 - 图16 Xc

Progress 进度条 - 图17 Delyan Haralanov

Progress 进度条 - 图18 bqy

Progress 进度条 - 图19 Alanscut

Progress 进度条 - 图20 Otto

Progress 进度条 - 图21 滑威

Progress 进度条 - 图22 kooriookami

Progress 进度条 - 图23 on the field of hope

Progress 进度条 - 图24 Hades-li

Progress 进度条 - 图25 hy