ElementPlus Progress 進(jìn)度條

2021-09-26 10:47 更新

Progress 進(jìn)度條

用于展示操作進(jìn)度,告知用戶當(dāng)前狀態(tài)和預(yù)期。

線形進(jìn)度條


Progress 組件設(shè)置percentage屬性即可,表示進(jìn)度條對(duì)應(yīng)的百分比,必填,必須在 0-100。通過 format 屬性來指定進(jìn)度條文字內(nèi)容。

<template>
  <el-progress :percentage="50"></el-progress>
  <el-progress :percentage="100" :format="format"></el-progress>
  <el-progress :percentage="100" status="success"></el-progress>
  <el-progress :percentage="100" status="warning"></el-progress>
  <el-progress :percentage="50" status="exception"></el-progress>
</template>

<script>
  export default {
    methods: {
      format(percentage) {
        return percentage === 100 ? '滿' : `${percentage}%`
      },
    },
  }
</script>

百分比內(nèi)顯

百分比不占用額外控件,適用于文件上傳等場(chǎng)景。


Progress 組件可通過 stroke-width 屬性更改進(jìn)度條的高度,并可通過 text-inside 屬性來將進(jìn)度條描述置于進(jìn)度條內(nèi)部。

<template>
  <el-progress
    :text-inside="true"
    :stroke-width="26"
    :percentage="70"
  ></el-progress>
  <el-progress
    :text-inside="true"
    :stroke-width="24"
    :percentage="100"
    status="success"
  ></el-progress>
  <el-progress
    :text-inside="true"
    :stroke-width="22"
    :percentage="80"
    status="warning"
  ></el-progress>
  <el-progress
    :text-inside="true"
    :stroke-width="20"
    :percentage="50"
    status="exception"
  ></el-progress>
</template>

自定義顏色

可以通過 color 設(shè)置進(jìn)度條的顏色,color 可以接受顏色字符串,函數(shù)和數(shù)組。


<template>
  <el-progress :percentage="percentage" :color="customColor"></el-progress>

  <el-progress
    :percentage="percentage"
    :color="customColorMethod"
  ></el-progress>

  <el-progress :percentage="percentage" :color="customColors"></el-progress>

  <el-progress :percentage="percentage2" :color="customColors"></el-progress>
  <div>
    <el-button-group>
      <el-button icon="el-icon-minus" @click="decrease"></el-button>
      <el-button icon="el-icon-plus" @click="increase"></el-button>
    </el-button-group>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        percentage: 20,
        percentage2: 0,
        customColor: '#409eff',
        customColors: [
          { color: '#f56c6c', percentage: 20 },
          { color: '#e6a23c', percentage: 40 },
          { color: '#5cb87a', percentage: 60 },
          { color: '#1989fa', percentage: 80 },
          { color: '#6f7ad3', percentage: 100 },
        ],
      }
    },
    methods: {
      customColorMethod(percentage) {
        if (percentage < 30) {
          return '#909399'
        } else if (percentage < 70) {
          return '#e6a23c'
        } else {
          return '#67c23a'
        }
      },
      increase() {
        this.percentage += 10
        if (this.percentage > 100) {
          this.percentage = 100
        }
      },
      decrease() {
        this.percentage -= 10
        if (this.percentage < 0) {
          this.percentage = 0
        }
      },
    },
    mounted() {
      setInterval(() => {
        this.percentage2 = (this.percentage2 % 100) + 10
      }, 500)
    },
  }
</script>

環(huán)形進(jìn)度條

Progress 組件可通過 type 屬性來指定使用環(huán)形進(jìn)度條,在環(huán)形進(jìn)度條中,還可以通過 width 屬性來設(shè)置其大小。


<template>
  <el-progress type="circle" :percentage="0"></el-progress>
  <el-progress type="circle" :percentage="25"></el-progress>
  <el-progress type="circle" :percentage="100" status="success"></el-progress>
  <el-progress type="circle" :percentage="70" status="warning"></el-progress>
  <el-progress type="circle" :percentage="50" status="exception"></el-progress>
</template>

儀表盤形進(jìn)度條


通過 type 屬性來指定使用儀表盤形進(jìn)度條。

<template>
  <el-progress
    type="dashboard"
    :percentage="percentage"
    :color="colors"
  ></el-progress>
  <el-progress
    type="dashboard"
    :percentage="percentage2"
    :color="colors"
  ></el-progress>
  <div>
    <el-button-group>
      <el-button icon="el-icon-minus" @click="decrease"></el-button>
      <el-button icon="el-icon-plus" @click="increase"></el-button>
    </el-button-group>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        percentage: 10,
        percentage2: 0,
        colors: [
          { color: '#f56c6c', percentage: 20 },
          { color: '#e6a23c', percentage: 40 },
          { color: '#5cb87a', percentage: 60 },
          { color: '#1989fa', percentage: 80 },
          { color: '#6f7ad3', percentage: 100 },
        ],
      }
    },
    methods: {
      increase() {
        this.percentage += 10
        if (this.percentage > 100) {
          this.percentage = 100
        }
      },
      decrease() {
        this.percentage -= 10
        if (this.percentage < 0) {
          this.percentage = 0
        }
      },
    },
    mounted() {
      setInterval(() => {
        this.percentage2 = (this.percentage2 % 100) + 10
      }, 500)
    },
  }
</script>

自定義內(nèi)容


通過默認(rèn)插槽添加自定義內(nèi)容。

<template>
  <el-progress :percentage="50">
    <el-button type="text">自定義內(nèi)容</el-button>
  </el-progress>
  <el-progress
    :text-inside="true"
    :stroke-width="20"
    :percentage="50"
    status="exception"
  >
    <span>自定義內(nèi)容</span>
  </el-progress>
  <el-progress type="circle" :percentage="100" status="success">
    <el-button type="success" icon="el-icon-check" circle></el-button>
  </el-progress>
  <el-progress type="dashboard" :percentage="80">
    <template #default="{ percentage }">
      <span class="percentage-value">{{ percentage }}%</span>
      <span class="percentage-label">當(dāng)前進(jìn)度</span>
    </template>
  </el-progress>
</template>

動(dòng)畫進(jìn)度條


Progress 組件設(shè)置 indeterminate 屬性控制進(jìn)度條運(yùn)動(dòng)。通過設(shè)置 duration 屬性可以控制運(yùn)動(dòng)速度。

<template>
  <el-progress :percentage="50" :indeterminate="true"></el-progress>
  <el-progress
    :percentage="100"
    :format="format"
    :indeterminate="true"
  ></el-progress>
  <el-progress
    :percentage="100"
    status="success"
    :indeterminate="true"
    :duration="5"
  ></el-progress>
  <el-progress
    :percentage="100"
    status="warning"
    :indeterminate="true"
    :duration="1"
  ></el-progress>
  <el-progress
    :percentage="50"
    status="exception"
    :indeterminate="true"
  ></el-progress>
</template>

<script>
  export default {
    methods: {
      format(percentage) {
        return percentage === 100 ? '滿' : `${percentage}%`
      },
    },
  }
</script>

Attributes

參數(shù)說明類型可選值默認(rèn)值
percentage百分比(必填)number0-1000
type進(jìn)度條類型stringline/circle/dashboardline
stroke-width進(jìn)度條的寬度,單位 pxnumber6
text-inside進(jìn)度條顯示文字內(nèi)置在進(jìn)度條內(nèi)(只在 type=line 時(shí)可用)booleanfalse
status進(jìn)度條當(dāng)前狀態(tài)stringsuccess/exception/warning
indeterminate是否為動(dòng)畫進(jìn)度條boolean-false
duration控制動(dòng)畫進(jìn)度條速度number-3
color進(jìn)度條背景色(會(huì)覆蓋 status 狀態(tài)顏色)string/function/array''
width環(huán)形進(jìn)度條畫布寬度(只在 type 為 circle 或 dashboard 時(shí)可用)number126
show-text是否顯示進(jìn)度條文字內(nèi)容booleantrue
stroke-linecapcircle/dashboard 類型路徑兩端的形狀stringbutt/round/squareround
format指定進(jìn)度條文字內(nèi)容function(percentage)

Slot

name說明
default自定義內(nèi)容,參數(shù)為 { percentage }



以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)