Skeleton骨架屏 - 图1

Skeleton 代码演示

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

何时使用

  • 当某个页面需要向用户显示警告的信息时。
  • 非浮层的静态展现形式,始终展现,不会自动消失,用户可以点击关闭。

代码演示

Skeleton骨架屏 - 图2

基本用法

最简单的占位效果。

  1. <template>
  2. <a-skeleton />
  3. </template>

Skeleton骨架屏 - 图3

复杂的组合

更复杂的组合。

  1. <template>
  2. <a-skeleton avatar :paragraph="{ rows: 4 }" />
  3. </template>

Skeleton骨架屏 - 图4

动画效果

显示动画效果。

  1. <template>
  2. <a-skeleton active />
  3. </template>

Skeleton骨架屏 - 图5

包含子组件

加载占位图包含子组件。

  1. <template>
  2. <div class="article">
  3. <a-skeleton :loading="loading">
  4. <div>
  5. <h4>Ant Design Vue, a design language</h4>
  6. <p>
  7. We supply a series of design principles, practical patterns and high quality design
  8. resources (Sketch and Axure), to help people create their product prototypes beautifully
  9. and efficiently.
  10. </p>
  11. </div>
  12. </a-skeleton>
  13. <a-button :disabled="loading" @click="showSkeleton">Show Skeleton</a-button>
  14. </div>
  15. </template>
  16. <script lang="ts">
  17. import { defineComponent, ref } from 'vue';
  18. export default defineComponent({
  19. setup() {
  20. const loading = ref<boolean>(false);
  21. const showSkeleton = () => {
  22. loading.value = true;
  23. setTimeout(() => {
  24. loading.value = false;
  25. }, 3000);
  26. };
  27. return {
  28. loading,
  29. showSkeleton,
  30. };
  31. },
  32. });
  33. </script>
  34. <style scoped>
  35. .article h4 {
  36. margin-bottom: 16px;
  37. }
  38. .article button {
  39. margin-top: 16px;
  40. }
  41. </style>

Skeleton骨架屏 - 图6

列表

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

  1. <template>
  2. <div>
  3. <a-switch :checked="!loading" @change="onChange" />
  4. <a-list item-layout="vertical" size="large" :data-source="listData">
  5. <template #renderItem="{ item }">
  6. <a-list-item key="item.title">
  7. <template v-if="!loading" #actions>
  8. <span v-for="{ type, text } in actions" :key="type">
  9. <component v-bind:is="type" style="margin-right: 8px"></component>
  10. {{ text }}
  11. </span>
  12. </template>
  13. <template #extra>
  14. <img
  15. v-if="!loading"
  16. width="272"
  17. alt="logo"
  18. src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
  19. />
  20. </template>
  21. <a-skeleton :loading="loading" active avatar>
  22. <a-list-item-meta :description="item.description">
  23. <template #title>
  24. <a :href="item.href">{{ item.title }}</a>
  25. </template>
  26. <template #avatar><a-avatar :src="item.avatar" /></template>
  27. </a-list-item-meta>
  28. {{ item.content }}
  29. </a-skeleton>
  30. </a-list-item>
  31. </template>
  32. </a-list>
  33. </div>
  34. </template>
  35. <script lang="ts">
  36. import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue';
  37. import { defineComponent, ref } from 'vue';
  38. interface DataItem {
  39. href: string;
  40. title: string;
  41. avatar: string;
  42. description: string;
  43. content: string;
  44. }
  45. const listData: DataItem[] = [];
  46. for (let i = 0; i < 3; i++) {
  47. listData.push({
  48. href: 'https://www.antdv.com/',
  49. title: `ant design vue part ${i}`,
  50. avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
  51. description:
  52. 'Ant Design, a design language for background applications, is refined by Ant UED Team.',
  53. content:
  54. '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.',
  55. });
  56. }
  57. export default defineComponent({
  58. components: {
  59. StarOutlined,
  60. LikeOutlined,
  61. MessageOutlined,
  62. },
  63. setup() {
  64. const loading = ref<boolean>(true);
  65. const actions = [
  66. { type: 'star-outlined', text: '156' },
  67. { type: 'like-outlined', text: '156' },
  68. { type: 'message-outlined', text: '2' },
  69. ];
  70. const onChange = (checked: boolean) => {
  71. loading.value = !checked;
  72. };
  73. return {
  74. loading,
  75. listData,
  76. actions,
  77. onChange,
  78. };
  79. },
  80. });
  81. </script>
  82. <style scoped>
  83. .skeleton-demo {
  84. border: 1px solid #f4f4f4;
  85. }
  86. </style>

API

Skeleton

属性说明类型默认值
active是否展示动画效果booleanfalse
avatar是否显示头像占位图boolean | SkeletonAvatarPropsfalse
loadingtrue 时,显示占位图。反之则直接展示子组件boolean-
paragraph是否显示段落占位图boolean | SkeletonParagraphPropstrue
title是否显示标题占位图boolean | SkeletonTitlePropstrue

SkeletonAvatarProps

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

SkeletonTitleProps

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

SkeletonParagraphProps

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