Skip to content

骨架屏 Skeleton

在需要等待加载内容的位置提供一个占位图形组合

何时使用

  • 网络较慢,需要长时间等待加载处理的情况下
  • 图文信息内容较多的列表/卡片中
  • 只在第一次加载数据的时候使用
  • 可以被 Spin 完全代替,但是在可用的场景下可以比 Spin 提供更好的视觉效果和用户体验

基本使用

Show Code
vue
<template>
  <Skeleton />
</template>

复杂的组合

Show Code
vue
<template>
  <Skeleton avatar :paragraph="{ rows: 4 }" />
</template>

包含子组件

Show Skeleton


Vue Amazing UI, a design language


We supply a series of design principles, practical patterns and high quality design resources, to help people create their product prototypes beautifully and efficiently.

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const loading = ref<boolean>(false)
const showSkeleton = () => {
  loading.value = true
  setTimeout(() => {
    loading.value = false
  }, 2000)
}
</script>
<template>
  <Button :loading="loading" @click="showSkeleton">Show Skeleton</Button>
  <br/>
  <br/>
  <Skeleton :loading="loading">
    <div>
      <h4>Vue Amazing UI, a design language</h4>
      <br/>
      <p>
        We supply a series of design principles, practical patterns and high quality design
        resources, to help people create their product prototypes beautifully and efficiently.
      </p>
    </div>
  </Skeleton>
</template>

自定义标题和段落

Show Code
vue
<template>
  <Skeleton avatar :title="{ width: '24%' }" :paragraph="{ rows: 4, width: ['48%', '72%', '96%', '60%'] }" />
</template>

按钮 / 输入框 / 图像 / 头像

animated:
Button Block:
Size:
small
middle
large
Button Shape:
default
round
circle
Avatar Shape:
square
circle
Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const animated = ref(false)
const block = ref(false)
const size = ref('middle')
const buttonShape = ref('default')
const avatarShape = ref('circle')
const sizeOptions = ref([
  {
    label: 'small',
    value: 'small'
  },
  {
    label: 'middle',
    value: 'middle'
  },
  {
    label: 'large',
    value: 'large'
  }
])
const buttonShapeOptions = ref([
  {
    label: 'default',
    value: 'default'
  },
  {
    label: 'round',
    value: 'round'
  },
  {
    label: 'circle',
    value: 'circle'
  }
])
const avatarShapeOptions = ref([
  {
    label: 'square',
    value: 'square'
  },
  {
    label: 'circle',
    value: 'circle'
  }
])
</script>
<template>
  <Flex :gap="32">
    <Flex vertical :gap="12" width="50%">
      <Skeleton :animated="animated" :button="{ shape: buttonShape, size: size, block: block }" />
      <Skeleton style="width: 200px" :animated="animated" :input="{ size: size }" />
      <Skeleton :animated="animated" image />
      <Skeleton :animated="animated" :avatar="{ shape: avatarShape, size: size }" :paragraph="{ rows: 2 }" />
    </Flex>
    <Flex vertical gap="large" width="50%">
      <Space gap="large">
        <Space align="center">
          animated:
          <Switch v-model="animated" />
        </Space>
        <Space align="center">
          Button Block:
          <Switch v-model="block" />
        </Space>
      </Space>
      <Space align="center">
        Size:
        <Radio :options="sizeOptions" v-model:value="size" button />
      </Space>
      <Space align="center">
        Button Shape:
        <Radio :options="buttonShapeOptions" v-model:value="buttonShape" button />
      </Space>
      <Space align="center">
        Avatar Shape:
        <Radio :options="avatarShapeOptions" v-model:value="avatarShape" button />
      </Space>
    </Flex>
  </Flex>
</template>

APIs

Skeleton

参数说明类型默认值
animated是否展示动画效果booleantrue
button是否使用按钮占位图boolean | SkeletonButtonPropsfalse
avatar是否显示头像占位图boolean | SkeletonAvatarPropsfalse
input是否使用输入框占位图boolean | SkeletonInputPropsfalse
image是否使用图像占位图booleanfalse
title是否显示标题占位图boolean | SkeletonTitlePropstrue
paragraph是否显示段落占位图boolean | SkeletonParagraphPropstrue
loadingtrue 时,显示占位图,反之则直接展示子组件booleantrue

SkeletonButtonProps Type

名称说明类型默认值
shape?指定按钮的形状'default' | 'round' | 'circle''default'
size?设置按钮的大小'small' | 'middle' | 'large''middle'
block?将按钮宽度调整为其父宽度的选项booleanfalse

SkeletonAvatarProps Type

名称说明类型默认值
shape指定头像的形状'circle' | 'square''circle'
size设置头像占位图的大小number | 'small' | 'middle' | 'large''middle'

SkeletonInputProps Type

名称说明类型默认值
size设置输入框的大小'small' | 'middle' | 'large''middle'

SkeletonTitleProps Type

名称说明类型默认值
width设置标题占位图的宽度number | string'38%'

SkeletonParagraphProps Type

名称说明类型默认值
rows设置段落占位图的行数number | stringavatar ? 2 : 3
width设置段落占位图的宽度,若为数组时则为对应的每行宽度,反之则是最后一行的宽度number | string | Array<number|string>'61%'

Released under the MIT License.