--- localeCode: zh-CN order: 67 category: 反馈类 title: Skeleton 骨架屏 icon: doc-skeleton brief: 在需要等待加载内容的位置提供的占位组件。 --- ## 概述 - `Avatar`:占位头像,默认为圆形,默认尺寸:Avatar medium: `width: 48px`,`height: 48px`。支持 Avatar 的 size 属性 (**v>=1.0**) - `Image`:占位图像,默认尺寸:`width: 100%`,`height: 100%`。 - `Title`:占位标题,默认尺寸:`width: 100%`, `height: 24px`。 - `Paragraph`:占位内容部分,默认尺寸:`width: 100%`,`height: 16px`,`margin-bottom: 10px`。 - `Button`:占位按钮,默认尺寸:`width: 115px`,`height: 32px`。 > 注意:默认样式均可通过 `className` 或 `style` 进行自定义。 ## 代码演示 ### 如何引入 ```jsx import import { Skeleton } from '@douyinfe/semi-ui'; ``` ### 基本使用 ```jsx live=true import React, { useState } from 'react'; import { Skeleton, Switch, Avatar, Button } from '@douyinfe/semi-ui'; () => { const [loading, setLoading] = useState(true); const showContent = () => { setLoading(!loading); }; return ( <> showContent()} /> 显示加载内容
} loading={loading}> U
} loading={loading}>
} loading={loading} >

Semi UI

} loading={loading}>

精心打磨每一个组件的用户体验,从用户的角度考虑每个组件的使用场景。


} loading={loading}> ); }; ``` ### 组合使用 图片和标题。 ```jsx live=true import React from 'react'; import { Skeleton } from '@douyinfe/semi-ui'; () => { const placeholder = (
); return (

Semi UI

); }; ``` 统计数字。 ```jsx live=true import React from 'react'; import { Skeleton, Descriptions } from '@douyinfe/semi-ui'; () => { const placeholder = (
); const data = [{ key: '实际用户数量', value: '1,480,000' }]; return ( ); }; ``` 头像和标题。 ```jsx live=true import React from 'react'; import { Skeleton, Avatar } from '@douyinfe/semi-ui'; () => { const placeholder = (
); return ( UI Semi UI ); }; ``` 居中段落和按钮。 ```jsx live=true import React from 'react'; import { Skeleton, Button } from '@douyinfe/semi-ui'; () => { const style = { display: 'flex', flexDirection: 'column', alignItems: 'center', width: '300px', marginBottom: '10px', }; const placeholder = (
); return (

Hi, Bytedance dance dance.

Hi, Bytedance dance dance.

); }; ``` 头像、标题和段落。 ```jsx live=true import React from 'react'; import { Skeleton, Avatar } from '@douyinfe/semi-ui'; () => { const style = { display: 'flex', alignItems: 'flex-start', }; const placeholder = (
); return (
UI

Semi UI

Hi, Bytedance dance dance.

Hi, Bytedance dance dance.

Hi, Bytedance dance dance.

); }; ``` 表格。 ```jsx live=true hideInDSM import React from 'react'; import { Skeleton, Table } from '@douyinfe/semi-ui'; () => { const data = { columns: [ { title: 'Name', dataIndex: 'name', }, { title: 'Age', dataIndex: 'age', }, { title: 'Address', dataIndex: 'address', }, ], content: [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park, New York No. 1 Lake Park', }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park', }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park', }, { key: '4', name: 'Disabled User', age: 99, address: 'Sidney No. 1 Lake Park', }, ], }; const skData = { columns: [1, 2, 3].map(key => { const item = {}; item.title = ; item.dataIndex = `${key}`; return item; }), dataSource: [1, 2, 3, 4].map(key => { const item = {}; item.key = key; [1, 2, 3].forEach(i => { const width = 50 * i; item[i] = ; }); return item; }), }; const placeholder = (
); return (
); }; ``` ### 加载动画 通过设置 `active` 属性可以展示动画效果。 ```jsx live=true hideInDSM import React from 'react'; import { Skeleton, Avatar } from '@douyinfe/semi-ui'; () => { const style = { display: 'flex', alignItems: 'flex-start', }; const placeholder = (
); return (
UI

Semi UI

Hi, Bytedance dance dance.

Hi, Bytedance dance dance.

Hi, Bytedance dance dance.

); }; ``` ## API 参考 ### Skeleton | 属性 | 说明 | 类型 | 默认值 | | ----------- | ------------------------------------------ | ---------- | ------ | | active | 是否展示动画效果 | boolean | false | | className | 类名 | string | - | | loading | 为 true 时,显示占位元素。反之则显示子组件 | boolean | true | | placeholder | 加载等待时的占位元素 | ReactNode | - | | style | 样式 | CSSProperties | - | ### Skeleton.Avatar > `Skeleton.Image`,`Skeleton.Title`,`Skeleton.Button` API 与 `Skeleton.Avatar` 相同 | 属性 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | className | 类名 | string | - | | size | 设置头像的大小,支持 `extra-extra-small`, `extra-small`、`small`、`medium`、`large`、`extra-large` **v>=1.0** | string | `medium` | | style | 样式 | CSSProperties | - | ### Skeleton.Paragraph | 属性 | 说明 | 类型 | 默认值 | | --------- | -------------------- | ------ | ------ | | className | 类名 | string | - | | rows | 设置段落占位图的行数 | number | 4 | | style | 样式 | CSSProperties | - | ## 设计变量