用于展示操作進(jìn)度,告知用戶當(dāng)前狀態(tài)和預(yù)期。
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>
百分比不占用額外控件,適用于文件上傳等場(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>
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>
通過 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>
通過默認(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>
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>
參數(shù) | 說明 | 類型 | 可選值 | 默認(rèn)值 |
---|---|---|---|---|
percentage | 百分比(必填) | number | 0-100 | 0 |
type | 進(jìn)度條類型 | string | line/circle/dashboard | line |
stroke-width | 進(jìn)度條的寬度,單位 px | number | — | 6 |
text-inside | 進(jìn)度條顯示文字內(nèi)置在進(jìn)度條內(nèi)(只在 type=line 時(shí)可用) | boolean | — | false |
status | 進(jìn)度條當(dāng)前狀態(tài) | string | success/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í)可用) | number | 126 | |
show-text | 是否顯示進(jìn)度條文字內(nèi)容 | boolean | — | true |
stroke-linecap | circle/dashboard 類型路徑兩端的形狀 | string | butt/round/square | round |
format | 指定進(jìn)度條文字內(nèi)容 | function(percentage) | — | — |
name | 說明 |
---|---|
default | 自定義內(nèi)容,參數(shù)為 { percentage } |
更多建議: