外观
Skeleton 骨架屏
在数据到达前预留正文或头像的位置,减小内容出现时的布局变化。
import { SSkeleton } from '@icecreamqaq/shadcn/skeleton'使用示例
基础用法
skeleton.vue组合式 API vue
<template>
<div class="profile">
<div :aria-busy="loading" aria-label="成员资料">
<template v-if="loading">
<s-skeleton class="title-bar" />
<s-skeleton class="text-bar" />
</template>
<template v-else>
<strong>林舟</strong>
<p>产品设计 · 杭州</p>
</template>
</div>
<s-button variant="outline" size="sm" @click="loading = !loading">
{{ loading ? '显示成员资料' : '显示加载占位' }}
</s-button>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { SButton } from '@icecreamqaq/shadcn/button'
import { SSkeleton } from '@icecreamqaq/shadcn/skeleton'
const loading = ref(true)
</script>
<style scoped>
.profile { display: grid; gap: 1rem; width: min(100%, 17rem); }
.profile button { justify-self: start; }
.title-bar { width: 55%; height: 1.25rem; }
.text-bar { width: 85%; height: 1rem; margin-top: 0.5rem; }
.profile p { margin: 0.5rem 0 0; }
</style>vue
<template>
<div class="profile">
<div :aria-busy="loading" aria-label="成员资料">
<template v-if="loading">
<s-skeleton class="title-bar" />
<s-skeleton class="text-bar" />
</template>
<template v-else>
<strong>林舟</strong>
<p>产品设计 · 杭州</p>
</template>
</div>
<s-button variant="outline" size="sm" @click="loading = !loading">
{{ loading ? '显示成员资料' : '显示加载占位' }}
</s-button>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { SButton } from '@icecreamqaq/shadcn/button'
import { SSkeleton } from '@icecreamqaq/shadcn/skeleton'
export default defineComponent({
components: { SButton, SSkeleton },
data() {
return { loading: true }
},
})
</script>
<style scoped>
.profile { display: grid; gap: 1rem; width: min(100%, 17rem); }
.profile button { justify-self: start; }
.title-bar { width: 55%; height: 1.25rem; }
.text-bar { width: 85%; height: 1rem; margin-top: 0.5rem; }
.profile p { margin: 0.5rem 0 0; }
</style>常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
SSkeleton.class | HTMLAttributes["class"] | 设置占位块的宽高与形状。组件提供圆角、底色和脉冲动效。 |
aria-busy | 原生 ARIA 属性 | 在加载中的内容容器标记忙碌状态,数据就绪后切换到实际内容。 |
完整 API
Skeleton1 个成员
属性
| 名称 | 类型 |
|---|---|
class | ClassValue |
分组导出
模板标签为 <s-skeleton>。
组件 SSkeleton