用于页面和区块的加载中状态。页面局部处于等待异步数据或正在渲染过程时,合适的加载动效会有效缓解用户的焦虑。
- 局部内容加载中,需要遮罩包裹已有内容时。
- 页面级或全屏加载中。
- 需要展示加载进度或自定义指示符时。
仅需一个旋转图标(行内、按钮内)时,使用更轻量的 Spinner 加载圈。
<template>
<Spin />
<Spin size="small" />
<Spin size="large" />
</template>
可以把内容内嵌到 Spin 中,将现有容器变为加载状态。
<script setup lang="ts">
import { ref } from "vue";
import { Spin, Alert, Switch } from "@reglow/reui";
const loading = ref(false);
</script>
<template>
<Spin :spinning="loading">
<Alert type="info" title="提示" description="这是提示内容" />
</Spin>
<p>加载状态:<Switch v-model="loading" /></p>
</template>
<template>
<Spin description="加载中..." size="large">
<div class="h-32 bg-muted/50 rounded" />
</Spin>
</template>
延迟显示 loading 效果。当 spinning 状态在 delay 时间内结束,则不显示 loading 状态。
<script setup lang="ts">
import { ref } from "vue";
import { Spin } from "@reglow/reui";
const loading = ref(false);
</script>
<template>
<Spin :spinning="loading" :delay="500">
<div class="h-32 bg-muted/50 rounded" />
</Spin>
</template>
通过 #indicator 插槽自定义加载指示符。
<script setup lang="ts">
import { Loader2 } from "lucide-vue-next";
</script>
<template>
<Spin :indicator="false">
<template #indicator>
<Loader2 class="size-6 animate-spin text-blue-500" />
</template>
</Spin>
</template>
展示进度条,percent="auto" 会预估一个循环进度。
<script setup lang="ts">
import { ref } from "vue";
import { Spin } from "@reglow/reui";
const percent = ref(0);
const auto = ref(false);
</script>
<template>
<Spin :percent="auto ? 'auto' : percent" size="small" />
<Spin :percent="auto ? 'auto' : percent" />
<Spin :percent="auto ? 'auto' : percent" size="large" />
</template>
fullscreen 属性创建带遮罩的页面级加载器。
<script setup lang="ts">
import { ref } from "vue";
import { Spin, Button } from "@reglow/reui";
const spinning = ref(false);
const percent = ref(0);
function showLoader() {
spinning.value = true;
percent.value = 0;
const interval = setInterval(() => {
percent.value += 5;
if (percent.value > 120) {
clearInterval(interval);
spinning.value = false;
percent.value = 0;
}
}, 100);
}
</script>
<template>
<Button @click="showLoader">显示全屏加载</Button>
<Spin :spinning="spinning" :percent="percent" fullscreen />
</template>
import { Spin } from "@reglow/reui";
| 参数 | 说明 | 类型 | 默认值 |
|---|
spinning | 是否为加载中状态 | boolean | true |
size | 组件大小 | "small" | "default" | "large" | "default" |
description | 自定义描述文案 | string | - |
delay | 延迟显示时间(毫秒),防止闪烁 | number | - |
indicator | 是否显示默认加载指示符 | boolean | true |
fullscreen | 全屏模式 | boolean | false |
percent | 展示进度 | number | "auto" | - |
class | 自定义类名 | string | - |
| 名称 | 说明 | 参数 |
|---|
default | 包裹的内容(非全屏模式) | - |
indicator | 自定义加载指示符 | - |
| size | 图标大小 | 文字大小 |
|---|
small | 14px (size-3.5) | text-xs |
default | 20px (size-5) | text-sm |
large | 32px (size-8) | text-base |