2020-08-13 15:18:26 +08:00
## Progreso
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
Progreso es usado para mostrar el estado de la operación actual e informar al usuario acerca de ésta.
### Barra de progreso lineal
:::demo Usa el atributo `percentage` para asignar el porcentaje. Este es **requerido** y tiene que ser un valor entre `0-100` . Puede personalizar el formato de texto estableciendo `format` .
```html
2021-09-07 15:59:49 +08:00
< 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 >
2020-08-13 15:18:26 +08:00
< script >
export default {
methods: {
format(percentage) {
2021-09-04 19:29:28 +08:00
return percentage === 100 ? 'Full' : `${percentage}%`
},
},
}
2020-08-13 15:18:26 +08:00
< / script >
2021-06-25 16:08:09 +08:00
<!--
< setup >
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
const format = (percentage) => (percentage === 100 ? 'Full' : `${percentage}%` );
return {
format,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Porcentaje interno
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
En este caso el porcentaje no toma espacio adicional.
:::demo El atributo `stroke-width` decide el ancho de la barra de progreso, y usa el atributo `text-inside` para poner la descripción dentro de la misma.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```html
2021-09-07 15:59:49 +08:00
< 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 >
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Color personalizado
Puede utilizar el atributo `color` para establecer el color de la barra de progreso.
:::demo
```html
2021-09-07 15:59:49 +08:00
< 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 >
2020-08-13 15:18:26 +08:00
< script >
export default {
data() {
return {
percentage: 20,
2021-06-17 11:33:26 +08:00
percentage2: 0,
2020-08-13 15:18:26 +08:00
customColor: '#409eff',
customColors: [
2021-09-04 19:29:28 +08:00
{ color: '#f56c6c', percentage: 20 },
{ color: '#e6a23c', percentage: 40 },
{ color: '#5cb87a', percentage: 60 },
{ color: '#1989fa', percentage: 80 },
{ color: '#6f7ad3', percentage: 100 },
],
}
2020-08-13 15:18:26 +08:00
},
methods: {
customColorMethod(percentage) {
if (percentage < 30 ) {
2021-09-04 19:29:28 +08:00
return '#909399'
2020-08-13 15:18:26 +08:00
} else if (percentage < 70 ) {
2021-09-04 19:29:28 +08:00
return '#e6a23c'
2020-08-13 15:18:26 +08:00
} else {
2021-09-04 19:29:28 +08:00
return '#67c23a'
2020-08-13 15:18:26 +08:00
}
},
increase() {
2021-09-04 19:29:28 +08:00
this.percentage += 10
2020-08-13 15:18:26 +08:00
if (this.percentage > 100) {
2021-09-04 19:29:28 +08:00
this.percentage = 100
2020-08-13 15:18:26 +08:00
}
},
decrease() {
2021-09-04 19:29:28 +08:00
this.percentage -= 10
2020-08-13 15:18:26 +08:00
if (this.percentage < 0 ) {
2021-09-04 19:29:28 +08:00
this.percentage = 0
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
2021-06-17 11:33:26 +08:00
},
mounted() {
setInterval(() => {
this.percentage2 = (this.percentage2 % 100) + 10
}, 500)
2021-09-04 19:29:28 +08:00
},
2020-08-13 15:18:26 +08:00
}
< / script >
2021-06-25 16:08:09 +08:00
<!--
< setup >
import { defineComponent, reactive, toRefs } from 'vue';
export default defineComponent({
setup() {
const state = reactive({
percentage: 20,
customColor: '#409eff',
customColors: [
{ color: '#f56c6c', percentage: 20 },
{ color: '#e6a23c', percentage: 40 },
{ color: '#5cb87a', percentage: 60 },
{ color: '#1989fa', percentage: 80 },
{ color: '#6f7ad3', percentage: 100 },
],
});
const customColorMethod = (percentage) => {
if (percentage < 30 ) {
return '#909399';
} if (percentage < 70 ) {
return '#e6a23c';
}
return '#67c23a';
};
const increase = () => {
state.percentage += 10;
if (state.percentage > 100) {
state.percentage = 100;
}
};
const decrease = () => {
state.percentage -= 10;
if (state.percentage < 0 ) {
state.percentage = 0;
}
};
return {
...toRefs(state),
customColorMethod,
increase,
decrease,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Barra de progreso circular
:::demo Puede asignar el atributo `type` como `circle` para usar la barra circular de progreso, y usar el atributo `width` para cambiar el tamaño del círculo.
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
```html
2021-09-07 15:59:49 +08:00
< 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 >
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
### Barra de progreso del panel de control
:::demo También puede especificar el atributo `type` a `dashboard` para usar la barra de progreso del panel de control.
```html
2021-09-07 15:59:49 +08:00
< 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 >
2020-08-13 15:18:26 +08:00
< script >
export default {
data() {
return {
percentage: 10,
2021-06-17 11:33:26 +08:00
percentage2: 0,
2020-08-13 15:18:26 +08:00
colors: [
2021-09-04 19:29:28 +08:00
{ color: '#f56c6c', percentage: 20 },
{ color: '#e6a23c', percentage: 40 },
{ color: '#5cb87a', percentage: 60 },
{ color: '#1989fa', percentage: 80 },
{ color: '#6f7ad3', percentage: 100 },
],
}
2020-08-13 15:18:26 +08:00
},
methods: {
increase() {
2021-09-04 19:29:28 +08:00
this.percentage += 10
2020-08-13 15:18:26 +08:00
if (this.percentage > 100) {
2021-09-04 19:29:28 +08:00
this.percentage = 100
2020-08-13 15:18:26 +08:00
}
},
decrease() {
2021-09-04 19:29:28 +08:00
this.percentage -= 10
2020-08-13 15:18:26 +08:00
if (this.percentage < 0 ) {
2021-09-04 19:29:28 +08:00
this.percentage = 0
2020-08-13 15:18:26 +08:00
}
2021-09-04 19:29:28 +08:00
},
2021-06-17 11:33:26 +08:00
},
mounted() {
setInterval(() => {
this.percentage2 = (this.percentage2 % 100) + 10
}, 500)
2021-09-04 19:29:28 +08:00
},
2020-08-13 15:18:26 +08:00
}
< / script >
2021-06-25 16:08:09 +08:00
<!--
< setup >
import { defineComponent, reactive, toRefs, onMounted } from 'vue';
export default defineComponent({
setup() {
const state = reactive({
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 },
],
});
const increase = () => {
state.percentage += 10;
if (state.percentage > 100) {
state.percentage = 100;
}
};
const decrease = () => {
state.percentage -= 10;
if (state.percentage < 0 ) {
state.percentage = 0;
}
};
onMounted(() => {
setInterval(() => {
state.percentage2 = (state.percentage2 % 100) + 10
}, 500)
});
return {
...toRefs(state),
increase,
decrease,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
2021-09-04 19:29:28 +08:00
2020-08-13 15:18:26 +08:00
:::
2021-02-05 16:27:44 +08:00
### Customized content
:::demo Use default slot to add customized content.
```html
2021-09-07 15:59:49 +08:00
< template >
< el-progress :percentage = "50" >
< el-button type = "text" > Content< / el-button >
< / el-progress >
< el-progress
:text-inside="true"
:stroke-width="20"
:percentage="50"
status="exception"
>
< span > Content< / 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" > Progressing< / span >
< / template >
< / el-progress >
< / template >
2021-02-05 16:27:44 +08:00
```
2021-09-04 19:29:28 +08:00
2021-02-05 16:27:44 +08:00
:::
2021-04-21 13:47:29 +08:00
### Indeterminate progress
:::demo Use `indeterminate` attribute to set indeterminate progress, with `duration` to control the animation duration.
```html
2021-09-07 15:59:49 +08:00
< 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 >
2021-04-21 13:47:29 +08:00
< script >
export default {
methods: {
format(percentage) {
2021-09-04 19:29:28 +08:00
return percentage === 100 ? 'Full' : `${percentage}%`
},
},
}
2021-04-21 13:47:29 +08:00
< / script >
2021-06-25 16:08:09 +08:00
<!--
< setup >
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
const format = (percentage) => (percentage === 100 ? 'Full' : `${percentage}%` );
return {
format,
};
},
});
< / setup >
-->
2021-04-21 13:47:29 +08:00
```
2021-09-04 19:29:28 +08:00
2021-04-21 13:47:29 +08:00
:::
2020-08-13 15:18:26 +08:00
### Atributos
2021-09-04 19:29:28 +08:00
2021-06-17 11:33:26 +08:00
| Atributo | Descripción | Tipo | Valores aceptado | Por defecto |
| -------------- | ------------------------------------------------------------------------------------------- | --------------------- | ------------------------- | ----------- |
| percentage | porcentaje, requerido | number | 0-100 | 0 |
| type | tipo de barra de progreso | string | line/circle/dashboard | line |
| stroke-width | ancho de la barra de progreso | number | — | 6 |
| text-inside | mostrar el porcentaje dentro de la barra de progreso, solo funciona cuando `type` es 'line' | boolean | — | false |
| status | estado actual de la barra de progreso | string | success/exception/warning | — |
| indeterminate | set indeterminate progress | boolean | - | false |
| duration | control the animation duration of indeterminate progress | number | - | 3 |
| color | color de fondo de la barra de progreso. Sobreescribe la propiedad `status` | string/function/array | — | '' |
| width | ancho del canvas que contiene la barra de progreso circula | number | — | 126 |
| show-text | mostrar porcentaje | boolean | — | true |
| stroke-linecap | circle/dashboard type shape at the end path | string | butt/round/square | round |
| format | personalizar el formato de texto estableciendo format | function(percentage) | — | — |
2021-02-05 16:27:44 +08:00
### Slot
2021-09-04 19:29:28 +08:00
2021-06-17 11:33:26 +08:00
| name | Description |
| ------- | ----------------------------------------------- |
2021-02-05 16:27:44 +08:00
| default | Customized content, parameter is { percentage } |