Appearance
Skeleton 骨架屏
在需要等待加载内容的位置提供一个占位图形组合。
代码演示
基础用法
vue
<template>
<a-skeleton />
</template>复杂的组合
vue
<template>
<a-skeleton avatar :paragraph="{ rows: 4 }" />
</template>动画效果
vue
<template>
<a-skeleton active />
</template>包含子组件
加载占位图包含子组件。
Ant Design Vue, a design language
We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.
vue
<template>
<a-space direction="vertical" style="width: 100%" :size="16">
<a-skeleton :loading="loading">
<div>
<h4>Ant Design Vue, a design language</h4>
<p>
We supply a series of design principles, practical patterns and high quality design
resources (Sketch and Axure), to help people create their product prototypes beautifully
and efficiently.
</p>
</div>
</a-skeleton>
<a-button :disabled="loading" @click="showSkeleton">Show Skeleton</a-button>
</a-space>
</template>
<script setup>
import { ref } from 'vue';
const loading = ref(false);
const showSkeleton = () => {
loading.value = true;
setTimeout(() => {
loading.value = false;
}, 3000);
};
</script>列表
在列表组件中使用加载占位符。
vue
<template>
<div>
<a-switch :checked="!loading" @change="onChange" />
<a-list item-layout="vertical" size="large" :data-source="listData">
<template #renderItem="{ item }">
<a-list-item key="item.title">
<template v-if="!loading" #actions>
<span v-for="({ icon, text }, index) in actions" :key="index">
<component :is="icon" style="margin-right: 8px"></component>
{{ text }}
</span>
</template>
<template #extra>
<img
v-if="!loading"
width="272"
alt="logo"
src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
/>
</template>
<a-skeleton :loading="loading" active avatar>
<a-list-item-meta :description="item.description">
<template #title>
<a :href="item.href">{{ item.title }}</a>
</template>
<template #avatar><a-avatar :src="item.avatar" /></template>
</a-list-item-meta>
{{ item.content }}
</a-skeleton>
</a-list-item>
</template>
</a-list>
</div>
</template>
<script setup>
import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue';
import { ref } from 'vue';
const listData = [];
for (let i = 0; i < 3; i++) {
listData.push({
href: 'https://www.antdv.com/',
title: `ant design vue part ${i}`,
avatar: 'https://joeschmoe.io/api/v1/random',
description:
'Ant Design, a design language for background applications, is refined by Ant UED Team.',
content:
'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.',
});
}
const loading = ref(true);
const actions = [
{
icon: StarOutlined,
text: '156',
},
{
icon: LikeOutlined,
text: '156',
},
{
icon: MessageOutlined,
text: '2',
},
];
const onChange = checked => {
loading.value = !checked;
};
</script>
<style scoped>
.skeleton-demo {
border: 1px solid #f4f4f4;
}
</style>按钮/头像/输入框/图像
骨架按钮、头像、输入框和图像。
vue
<template>
<a-space>
<a-skeleton-button :active="active" :size="size" :shape="buttonShape" :block="block" />
<a-skeleton-avatar :active="active" :size="size" :shape="avatarShape" />
<a-skeleton-input style="width: 200px" :active="active" :size="size" />
</a-space>
<br />
<br />
<a-skeleton-button :active="active" :size="size" :shape="buttonShape" :block="block" />
<br />
<br />
<a-skeleton-image />
<a-divider />
<a-form layout="inline" style="margin: 16px 0">
<a-form-item label="Active">
<a-switch v-model:checked="active" />
</a-form-item>
<a-form-item label="Button Block">
<a-switch v-model:checked="block" />
</a-form-item>
<a-form-item label="Size">
<a-radio-group v-model:value="size">
<a-radio-button value="default">Default</a-radio-button>
<a-radio-button value="large">Large</a-radio-button>
<a-radio-button value="small">Small</a-radio-button>
</a-radio-group>
</a-form-item>
<a-form-item label="Button Shape">
<a-radio-group v-model:value="buttonShape">
<a-radio-button value="default">Default</a-radio-button>
<a-radio-button value="round">Round</a-radio-button>
<a-radio-button value="circle">Circle</a-radio-button>
</a-radio-group>
</a-form-item>
<a-form-item label="Avatar Shape">
<a-radio-group v-model:value="avatarShape">
<a-radio-button value="square">Square</a-radio-button>
<a-radio-button value="circle">Circle</a-radio-button>
</a-radio-group>
</a-form-item>
</a-form>
</template>
<script setup>
import { ref } from 'vue';
const active = ref(false);
const block = ref(false);
const size = ref('default');
const buttonShape = ref('default');
const avatarShape = ref('circle');
</script>API
Skeleton
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| active | 是否展示动画效果 | boolean | false |
| avatar | 是否显示头像占位图 | boolean | SkeletonAvatarProps | false |
| loading | 为 true 时,显示占位图。反之则直接展示子组件 | boolean | - |
| paragraph | 是否显示段落占位图 | boolean | SkeletonParagraphProps | true |
| title | 是否显示标题占位图 | boolean | SkeletonTitleProps | true |
SkeletonAvatarProps
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| shape | 指定头像的形状 | circle | square | - |
| size | 设置头像占位图的大小 | number | large | small | default | - |
SkeletonTitleProps
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| width | 设置标题占位图的宽度 | number | string | - |
SkeletonParagraphProps
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| rows | 设置段落占位图的行数 | number | - |
| width | 设置段落占位图的宽度,若为数组时则为对应的每行宽度,反之则是最后一行的宽度 | number | string | Array<number | string> | - |
SkeletonButtonProps
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| active | 是否展示动画效果 | boolean | false |
| block | 将按钮宽度调整为其父宽度的选项 | boolean | false |
| shape | 指定按钮的形状 | circle | round | default | - |
| size | 设置按钮的大小 | large | small | default | - |
SkeletonInputProps
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| active | 是否展示动画效果 | boolean | false |
| size | 设置输入框的大小 | large | small | default | - |

