Skip to content

Skeleton 骨架屏

宫格骨架屏

通过 row-col 组合多行多列占位结构,可以构造宫格骨架屏。

主题类型

通过 `theme` 设置不同骨架主题,常用于文本、头像、图片、段落等场景。

单元格骨架屏

可以组合头像、矩形块与文本行,模拟常见单元格列表布局。

html
<view style="display: flex">
  <wd-skeleton :row-col="[{ size: '48px', type: 'circle' }]" />
  <wd-skeleton :custom-style="{ width: '100%', marginLeft: '12px' }" :row-col="[{ width: '50%' }, { width: '100%' }]" />
</view>

<view style="display: flex; margin-top: 20px">
  <wd-skeleton :row-col="[{ size: '48px', type: 'rect' }]" />
  <wd-skeleton :custom-style="{ width: '100%', marginLeft: '12px' }" :row-col="[{ width: '50%' }, { width: '100%' }]" />
</view>

图片组合骨架屏

可以结合 row-col 自定义图片卡片与图文混排占位结构。

html
<wd-skeleton :row-col="[{ height: '171px' }, 1, { width: '107px' }, [{ width: '93px' }, { width: '32px', marginLeft: '41px' }]]" />
### 渐变加载动画
## 组件样式
设置 `animation="gradient"` 开启渐变加载动画。
### 自定义行列

通过 `row-col` 自定义每一行占位结构,可组合宽高、圆角、类型等配置。
```html
<wd-skeleton :row-col="[{ width: '100%' }, { width: '80%' }, { width: '60%' }]" />
### 闪烁加载动画

设置 `animation="flashed"` 开启闪烁加载动画。

```html
<view style="display: flex">
  <wd-skeleton :row-col="[{ size: '48px', type: 'circle' }]" />
  <wd-skeleton :custom-style="{ width: '100%', marginLeft: '12px' }" animation="flashed" theme="paragraph" />
</view>

插槽内容

通过默认插槽写入实际内容。loadingtrue 时显示骨架屏,切换为 false 后显示插槽内容。

动画效果

设置 animation 开启动画效果,可选值为 gradientflashed

自定义内容

设置 loadingfalse 后,显示默认插槽内容。

html
<wd-skeleton :row-col="grid" :loading="showContent">
  <wd-grid>
    <wd-grid-item icon-size="32px" icon="picture" text="文字" />
    <wd-grid-item icon-size="32px" icon="picture" text="文字" />
    <wd-grid-item icon-size="32px" icon="picture" text="文字" />
    <wd-grid-item icon-size="32px" icon="picture" text="文字" />
    <wd-grid-item icon-size="32px" icon="picture" text="文字" />
  </wd-grid>
</wd-skeleton>
ts
const showContent = ref(true)

Attributes

参数说明类型默认值
theme骨架屏主题,可选值为 textavatarparagraphimageSkeletonTheme'text'
row-col自定义每行占位配置,用于设置行列数量、宽高、间距、圆角和占位类型等SkeletonRowCol[][]
loading是否显示骨架屏booleantrue
animation动画类型,可选值为 gradientflashedSkeletonAnimation''
custom-class自定义样式类名string | string[] | Record<string, boolean>''
custom-style自定义内联样式CSSProperties{}

Slots

name说明
defaultloading 结束后展示的实际内容

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-skeleton-row-margin-bottom$spacing-loose行间距
--wot-skeleton-col-bg$filled-strong占位块背景色
--wot-skeleton-text-height$n-16文本占位高度
--wot-skeleton-rect-height$n-16矩形占位高度
--wot-skeleton-circle-height$n-48圆形占位尺寸
--wot-skeleton-text-border-radius$radius-small文本占位圆角
--wot-skeleton-rect-border-radius$radius-main矩形占位圆角
--wot-skeleton-circle-border-radius$radius-radius-full圆形占位圆角
--wot-skeleton-animation-gradient$filled-bottom渐变动画高亮色
--wot-skeleton-animation-flashed$filled-bottom闪烁动画高亮色
--wot-skeleton-animation-flashed-opacity$opacity-backdrop闪烁动画透明度

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.