翻譯進行中
本頁尚未翻譯為繁體中文,以下顯示簡體中文原文。範例的預設元件文字仍使用繁體中文。
Skeleton 骨架屏
真实内容就绪前展示骨架结构;关闭 loading 后挂载默认内容。
引入
uni-app 配置 easycom 后使用 <hui-skeleton>。公开类型和函数从 @nscode/handy-uni 导入;普通 Vue 3 安装 @nscode/handy-uni/web 预览插件。
示例
示例可独立运行;交互结果直接显示在页面。
vue
<template>
<view>
<hui-space direction="vertical" fill>
<hui-button custom-class="hui-space__item" @click="loading = !loading"
>切换加载 / Toggle loading</hui-button
>
<hui-skeleton custom-class="hui-space__item" :loading="loading" avatar title image :rows="3"
><text>内容已就绪 / Content ready</text></hui-skeleton
>
<hui-skeleton
custom-class="hui-space__item"
:animated="false"
:row-width="['90%', '70%']"
:rows="2"
/>
<hui-skeleton custom-class="hui-space__item"
><template #template
><hui-skeleton-item variant="circle" /><hui-skeleton-item :width="160" /></template
></hui-skeleton>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref(true)
</script>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
loading | boolean | true | false 时显示默认插槽的真实内容 |
animated | boolean | true | 闪光动画;系统开了“减少动态效果”时 H5、Web 版自动关(prefers-reduced-motion) |
rows | number | 3 | 段落行数 |
rowWidth | number | string | (number | string)[] | '100%' | 每行宽度;数组按行取,最后一行默认 60% |
title | boolean | false | 段落上方的标题条 |
titleWidth | number | string | '40%' | 标题占位宽度,数字按 px。 |
avatar | boolean | false | 左侧头像占位 |
avatarSize | SkeletonAvatarSize | 'default' | 和 相关组件 的尺寸档一致(48/40/32) |
avatarShape | 'circle' | 'square' | 'circle' | 头像占位形状:circle 或 square。 |
image | boolean | false | 段落上方的整宽图片占位(卡片、瀑布流的封面) |
imageRatio | number | 16 / 9 | 图片占位的宽高比 |
round | boolean | false | 条和图片占位用大圆角 |
根节点类名和样式使用 customClass、customStyle。尺寸数字按 px,时长除明确说明外按 ms。
Events
无。
Slots
| 插槽 | 作用域 |
|---|---|
template | — |
default | — |
方法
无。
类型
SkeletonAvatarSize、SkeletonProps、SkeletonEmits.
平台说明
骨架和 Image 加载态共享背景及闪光 mixin。浏览器减少动态效果偏好会关闭动画;微信、App 按 animated 控制。骨架块 aria-hidden,整体通过 aria-busy 与加载文字播报。
设备冒烟清单.