Spinner
The Spinner component can be used to display a "loading" status.
Basic
Example code
vue
<template>
<epp-spinner />
</template>
<script lang="ts" setup>
</script>
Size
The size
prop of the Spinner
component can accept common size values.
You can also pass in custom values to define the size.
vue
<template>
<epp-spinner size="36px" />
</template>
<script lang="ts" setup>
</script>
Color
Use the color
prop to pass in a color value.
Spinners are usually used in combination with other element components, so built-in status colors are not necessary. However, you can use status colors via var(--el-color-danger)
.
vue
<template>
<el-space block size="large">
<epp-spinner color="var(--el-color-danger)">
<el-icon><Present /></el-icon>
</epp-spinner>
<epp-spinner color="#4a7fb1">
<el-icon><ShoppingBag /></el-icon>
</epp-spinner>
<epp-spinner color="#b14a4a">
<el-icon><Flag /></el-icon>
</epp-spinner>
<epp-spinner color="#b9bd47">
<el-icon><GoodsFilled /></el-icon>
</epp-spinner>
</el-space>
</template>
<script lang="ts" setup>
import { Present, ShoppingBag, Flag, GoodsFilled } from '@element-plus/icons-vue';
</script>
Custom Content
The Spinner
provides a default slot where you can insert any content.
转圈
Example code
vue
<template>
<el-space block size="large">
<epp-spinner color="var(--el-color-danger)" />
<epp-spinner color="#999">
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<epp-spinner color="var(--el-color-danger)">转圈</epp-spinner>
<epp-spinner animation="none" color="var(--el-color-primary)">
<svg viewBox="0 0 105 105" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<circle cx="12.5" cy="12.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="0s"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="12.5" cy="52.5" r="12.5" fill-opacity="0.5">
<animate
attributeName="fill-opacity"
begin="100ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="52.5" cy="12.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="300ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="52.5" cy="52.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="600ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="92.5" cy="12.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="800ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="92.5" cy="52.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="400ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="12.5" cy="92.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="700ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="52.5" cy="92.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="500ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="92.5" cy="92.5" r="12.5">
<animate
attributeName="fill-opacity"
begin="200ms"
dur="1s"
values="1;.2;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
</svg>
</epp-spinner>
<epp-spinner animation="none" color="var(--el-color-success)">
<svg viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<circle cx="15" cy="15" r="15">
<animate
attributeName="r"
from="15"
to="15"
begin="0s"
dur="0.8s"
values="15;9;15"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="fill-opacity"
from="1"
to="1"
begin="0s"
dur="0.8s"
values="1;.5;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="60" cy="15" r="9" fill-opacity="0.3">
<animate
attributeName="r"
from="9"
to="9"
begin="0s"
dur="0.8s"
values="9;15;9"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="fill-opacity"
from="0.5"
to="0.5"
begin="0s"
dur="0.8s"
values=".5;1;.5"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="105" cy="15" r="15">
<animate
attributeName="r"
from="15"
to="15"
begin="0s"
dur="0.8s"
values="15;9;15"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="fill-opacity"
from="1"
to="1"
begin="0s"
dur="0.8s"
values="1;.5;1"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
</svg>
</epp-spinner>
<epp-spinner animation="none" color="var(--el-color-warning)">
<svg viewBox="0 0 135 140" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<rect y="10" width="15" height="120" rx="6">
<animate
attributeName="height"
begin="0.5s"
dur="1s"
values="120;110;100;90;80;70;60;50;40;140;120"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="y"
begin="0.5s"
dur="1s"
values="10;15;20;25;30;35;40;45;50;0;10"
calcMode="linear"
repeatCount="indefinite"
/>
</rect>
<rect x="30" y="10" width="15" height="120" rx="6">
<animate
attributeName="height"
begin="0.25s"
dur="1s"
values="120;110;100;90;80;70;60;50;40;140;120"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="y"
begin="0.25s"
dur="1s"
values="10;15;20;25;30;35;40;45;50;0;10"
calcMode="linear"
repeatCount="indefinite"
/>
</rect>
<rect x="60" width="15" height="140" rx="6">
<animate
attributeName="height"
begin="0s"
dur="1s"
values="120;110;100;90;80;70;60;50;40;140;120"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="y"
begin="0s"
dur="1s"
values="10;15;20;25;30;35;40;45;50;0;10"
calcMode="linear"
repeatCount="indefinite"
/>
</rect>
<rect x="90" y="10" width="15" height="120" rx="6">
<animate
attributeName="height"
begin="0.25s"
dur="1s"
values="120;110;100;90;80;70;60;50;40;140;120"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="y"
begin="0.25s"
dur="1s"
values="10;15;20;25;30;35;40;45;50;0;10"
calcMode="linear"
repeatCount="indefinite"
/>
</rect>
<rect x="120" y="10" width="15" height="120" rx="6">
<animate
attributeName="height"
begin="0.5s"
dur="1s"
values="120;110;100;90;80;70;60;50;40;140;120"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="y"
begin="0.5s"
dur="1s"
values="10;15;20;25;30;35;40;45;50;0;10"
calcMode="linear"
repeatCount="indefinite"
/>
</rect>
</svg>
</epp-spinner>
<epp-spinner animation="none" color="var(--el-color-info)">
<svg viewBox="0 0 57 57" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<circle r="6">
<animate
attributeName="cy"
begin="0s"
dur="2.2s"
values="50;5;50;50"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="cx"
begin="0s"
dur="2.2s"
values="5;27;49;5"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle r="6">
<animate
attributeName="cy"
begin="0s"
dur="2.2s"
from="5"
to="5"
values="5;50;50;5"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="cx"
begin="0s"
dur="2.2s"
from="27"
to="27"
values="27;49;5;27"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle r="6">
<animate
attributeName="cy"
begin="0s"
dur="2.2s"
values="50;50;5;50"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="cx"
from="49"
to="49"
begin="0s"
dur="2.2s"
values="49;5;27;49"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
</svg>
</epp-spinner>
</el-space>
</template>
<script lang="ts" setup>
import { Present } from '@element-plus/icons-vue';
</script>
Rotation Direction
The animation
prop can control the direction of automatic rotation.
向右旋转(Rotate right)
向左旋转(Rotate left)
禁止旋转(No Rotation)
If your custom graphic already has a rotation animation, you can use animation="none"
to turn off the Spinner component's rotation effect.
vue
<template>
<el-space block size="large">
<el-space size="large" direction="vertical">
<epp-spinner animation="around-right">
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<p>向右旋转(Rotate right)</p>
</el-space>
<el-space size="large" direction="vertical">
<epp-spinner animation="around-left">
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<p>向左旋转(Rotate left)</p>
</el-space>
<el-space size="large" direction="vertical">
<epp-spinner animation="none">
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<p>禁止旋转(No Rotation)</p>
</el-space>
</el-space>
</template>
<script lang="ts" setup>
import { Present } from '@element-plus/icons-vue';
</script>
Animation Duration
The duration
prop can control the duration of the animation.
默认(Default) 2s
500ms
12s
If your custom graphic already has a rotation animation, you can use animation="none"
to turn off the Spinner component's rotation effect.
vue
<template>
<el-space block size="large">
<el-space size="large" direction="vertical">
<epp-spinner>
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<p>默认(Default) 2s</p>
</el-space>
<el-space size="large" direction="vertical">
<epp-spinner duration="500ms">
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<p>500ms</p>
</el-space>
<el-space size="large" direction="vertical">
<epp-spinner duration="12s">
<el-icon>
<Present />
</el-icon>
</epp-spinner>
<p>12s</p>
</el-space>
</el-space>
</template>
<script lang="ts" setup>
import { Present } from '@element-plus/icons-vue';
</script>
Status Feedback
In addition to displaying a rotating graphic, the Spinner can provide feedback on a result based on the status
variable.
默认方式(Default)
slot方式(Slot)
提交错误
The Spinner provides four status slots: success
, warning
, error
, and info
. You can customize the content based on the type.
vue
<template>
<el-row>
<el-col :span="12">
<el-space direction="vertical">
<h6>默认方式(Default)</h6>
<epp-spinner :status="status" @click="handle('')" />
<el-space size="small">
<el-button :disabled="disabled" @click="handle('success')">Success</el-button>
<el-button :disabled="disabled" @click="handle('error')">Error</el-button>
<el-button :disabled="disabled" @click="handle('warning')">Warning</el-button>
<el-button :disabled="disabled" @click="handle('info')">Info</el-button>
</el-space>
</el-space>
</el-col>
<el-col :span="12">
<el-space direction="vertical">
<h6>slot方式(Slot)</h6>
<epp-spinner :status="status1" @click="handle1('')">
<template #error>提交错误</template>
<template #success>
<el-icon>
<GoodsFilled />
</el-icon>
</template>
<template #warning>
<el-icon>
<AlarmClock />
</el-icon>
</template>
<template #info>
<el-icon>
<Present />
</el-icon>
</template>
</epp-spinner>
<el-space size="small">
<el-button :disabled="disabled1" @click="handle1('success')">Success</el-button>
<el-button :disabled="disabled1" @click="handle1('error')">Error</el-button>
<el-button :disabled="disabled1" @click="handle1('warning')">Warning</el-button>
<el-button :disabled="disabled1" @click="handle1('info')">Info</el-button>
</el-space>
</el-space>
</el-col>
</el-row>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { Present, AlarmClock, GoodsFilled } from '@element-plus/icons-vue';
const disabled = ref(false);
const disabled1 = ref(false);
const status = ref('');
const status1 = ref('');
const handle = (s) => {
status.value = s;
disabled.value = true;
setTimeout(() => {
status.value = '';
disabled.value = false;
}, 2000);
};
const handle1 = (s) => {
status1.value = s;
disabled1.value = true;
setTimeout(() => {
status1.value = '';
disabled1.value = false;
}, 2000);
};
</script>
Attributes
Parameter | Description | Type | Optional Values | Default Value |
---|---|---|---|---|
size | Size | string | - | — |
color | Color | string | — | |
animation | Rotation direction | string | around-left / around-right / none | around-right |
duration | Animation duration | string | s / ms | 2s |
status | Status feedback | string | success / error / warning / info |
Slots
Name | Description |
---|---|
- | Default slot |
success | Success status slot |
error | Error status slot |
warning | Warning status slot |
info | Information/Info status slot |