Skeleton骨架屏

Skeleton 代码演示

警告提示,展现需要关注的信息。

何时使用

  • 当某个页面需要向用户显示警告的信息时。

  • 非浮层的静态展现形式,始终展现,不会自动消失,用户可以点击关闭。

代码演示

基本用法

最简单的占位效果。

<​template>  <​a-skeleton /><​/template>

复杂的组合

更复杂的组合。

<​template>  <​a-skeleton avatar :paragraph="{ rows: 4 }" /><​/template>

动画效果

显示动画效果。

<​template>  <​a-skeleton active /><​/template>

包含子组件

加载占位图包含子组件。

<​template>  <​div class="article">    <​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>  <​/div><​/template><​script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({  setup() {    const loading = ref<​boolean>(false);    const showSkeleton = () => {      loading.value = true;      setTimeout(() => {        loading.value = false;      }, 3000);    };    return {      loading,      showSkeleton,    };  },});<​/script><​style scoped>.article h4 {  margin-bottom: 16px;}.article button {  margin-top: 16px;}<​/style>

列表

在列表组件中使用加载占位符。

<​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="{ type, text } in actions" :key="type">              <​component v-bind:is="type" 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 lang="ts">import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue';import { defineComponent, ref } from 'vue';interface DataItem {  href: string;  title: string;  avatar: string;  description: string;  content: string;}const listData: DataItem[] = [];for (let i = 0; i < 3; i++) {  listData.push({    href: 'https://www.antdv.com/',    title: `ant design vue part ${i}`,    avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',    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.',  });}export default defineComponent({  components: {    StarOutlined,    LikeOutlined,    MessageOutlined,  },  setup() {    const loading = ref<​boolean>(true);    const actions = [      { type: 'star-outlined', text: '156' },      { type: 'like-outlined', text: '156' },      { type: 'message-outlined', text: '2' },    ];    const onChange = (checked: boolean) => {      loading.value = !checked;    };    return {      loading,      listData,      actions,      onChange,    };  },});<​/script><​style scoped>.skeleton-demo {  border: 1px solid #f4f4f4;}<​/style>

API

Skeleton

属性 说明 类型 默认值
active 是否展示动画效果 boolean false

| avatar | 是否显示头像占位图 | boolean | SkeletonAvatarProps | false | |---|---|---|---|

loading 为 true 时,显示占位图。反之则直接展示子组件 boolean -

| paragraph | 是否显示段落占位图 | boolean | SkeletonParagraphProps | true | |---|---|---|---|

| title | 是否显示标题占位图 | boolean | SkeletonTitleProps | true | |---|---|---|---|

SkeletonAvatarProps

属性 说明 类型 默认值

| size | 设置头像占位图的大小 | number | large | small | default | - | |---|---|---|---|

| shape | 指定头像的形状 | circle | square | - | |---|---|---|---|

SkeletonTitleProps

属性 说明 类型 默认值

| width | 设置标题占位图的宽度 | number | string | - | |---|---|---|---|

SkeletonParagraphProps

属性 说明 类型 默认值
rows 设置段落占位图的行数 number -

| width | 设置段落占位图的宽度,若为数组时则为对应的每行宽度,反之则是最后一行的宽度 | number | string | Array<​number | string> | - | |---|---|---|---|