Skip to content

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是否展示动画效果booleanfalse
avatar是否显示头像占位图boolean | SkeletonAvatarPropsfalse
loading为 true 时,显示占位图。反之则直接展示子组件boolean-
paragraph是否显示段落占位图boolean | SkeletonParagraphPropstrue
title是否显示标题占位图boolean | SkeletonTitlePropstrue

SkeletonAvatarProps

属性说明类型默认值
shape指定头像的形状circle | square-
size设置头像占位图的大小number | large | small | default-

SkeletonTitleProps

属性说明类型默认值
width设置标题占位图的宽度number | string-

SkeletonParagraphProps

属性说明类型默认值
rows设置段落占位图的行数number-
width设置段落占位图的宽度,若为数组时则为对应的每行宽度,反之则是最后一行的宽度number | string | Array<number | string>-

SkeletonButtonProps

属性说明类型默认值
active是否展示动画效果booleanfalse
block将按钮宽度调整为其父宽度的选项booleanfalse
shape指定按钮的形状circle | round | default-
size设置按钮的大小large | small | default-

SkeletonInputProps

属性说明类型默认值
active是否展示动画效果booleanfalse
size设置输入框的大小large | small | default-