LoadingPage 加载中页面
介绍
LoadingPage 是一个全屏显示加载状态的组件,用于在数据加载时向用户提供视觉反馈。
导入
js
import LoadingPage from '@/components/display/loading/LoadingPage.vue'用法
基础用法
基础的加载页面组件,显示加载动画和默认的"加载中"文本。组件默认会占满父级。
vue
<template>
<view style="position: relative; height: 300px; background-color: #f5f5f5;">
<LoadingPage v-if="showLoading" />
<text style="padding: 20rpx;font-size:58rpx;">这里是内容区域这里是内容区域这里是内容区域这里是内容区域这里是内容区域</text>
</view>
<Button
text="显示加载页面"
type="primary"
@click="simulateLoading()"
style="margin-top: 20rpx;"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import LoadingPage from '@/components/display/loading/LoadingPage.vue';
import Button from '@/components/basic/Button.vue';
// 是否显示加载页面
const showLoading = ref(false);
// 模拟加载操作
function simulateLoading(duration: number = 2000) {
showLoading.value = true;
setTimeout(() => {
showLoading.value = false;
}, duration);
}
</script>自定义加载文本
通过 loading-text 属性自定义加载提示文本。
vue
<template>
<view style="position: relative; height: 200px; background-color: #f5f5f5;">
<text style="padding: 20rpx;font-size:58rpx;">这里是内容区域这里是内容区域这里是内容区域这里是内容区域这里是内容区域</text>
<LoadingPage loading-text="正在加载数据..." />
</view>
</template>自定义颜色
通过 indicator-color 属性自定义加载器的颜色。
vue
<template>
<view style="display: flex; gap: 20rpx;">
<view style="position: relative; height: 150px; width: 50%; background-color: #f5f5f5;">
<LoadingPage loading-text="primary" indicator-color="primary" />
</view>
<view style="position: relative; height: 150px; width: 50%; background-color: #f5f5f5;">
<LoadingPage loading-text="success" indicator-color="success" />
</view>
</view>
<view style="display: flex; gap: 20rpx; margin-top: 20rpx;">
<view style="position: relative; height: 150px; width: 50%; background-color: #f5f5f5;">
<LoadingPage loading-text="warning" indicator-color="warning" />
</view>
<view style="position: relative; height: 150px; width: 50%; background-color: #f5f5f5;">
<LoadingPage loading-text="danger" indicator-color="danger" />
</view>
</view>
</template>自定义文本样式
通过 loading-text-props 属性自定义加载文本的样式。
vue
<template>
<view style="position: relative; height: 200px; background-color: #f5f5f5;">
<LoadingPage
loading-text="请稍候..."
:loading-text-props="{
fontSize: 32,
fontWeight: 'bold',
color: 'primary'
}"
/>
</view>
</template>自定义容器背景
通过 inner-style 属性自定义加载页面容器的样式。
vue
<template>
<view style="position: relative; height: 200px; background-color: #e0f7fa;">
<LoadingPage
loading-text="半透明背景"
:inner-style="{ backgroundColor: 'rgba(255, 255, 255, 0.7)' }"
/>
</view>
</template>自定义下方内容插槽
通过默认插槽添加自定义内容。
vue
<template>
<view style="position: relative; height: 200px; background-color: #f5f5f5;">
<LoadingPage>
<Height :height="20" />
<Button text="取消" type="primary" />
</LoadingPage>
</view>
</template>API 参考
LoadingPage
全屏加载状态组件。
Props
| 名称 | 说明 | 类型 | 必填 | 默认值 |
|---|---|---|---|---|
| loadingText | 加载器下方文字 | string | 否 | '加载中' |
| loadingTextProps | 加载器下方文字样式 | object | 否 | - |
| indicatorColor | 加载器颜色 | string | 否 | 'primary' |
| indicatorStyle | 加载器样式 | object | 否 | - |
| innerStyle | 容器自定义样式 | object | 否 | - |
Slots
| 名称 | 说明 |
|---|---|
| default | 加载器下方的自定义内容 |
主题变量
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| LoadingPageBackgroundColor | string | mask.white | 加载页面背景色 |
| LoadingPageIndicatorColor | string | primary | 加载器颜色 |