Files
element-plus/docs/en-US/component/skeleton.md
chenweiyi 3eb734ccc4 feat(components): [skeleton] throttle supports values ​​as object (#17041)
* fix(components): [skeleton] `throttle` property not working

* fix: lint fix

* feat: add func & doc & test

* feat: remove test modify

* feat: increase document examples, improve document descriptions

* fix(components): [skeleton] `throttle` property not working

* fix: lint fix

* feat: add func & doc & test

* feat: remove test modify

* feat: increase document examples, improve document descriptions

* feat: 重构`useThrottleRender`钩子以提高代码可读性和效率

- 简化了对`throttle`参数的判断逻辑,通过`isNumber`函数判断是否为数字
- 将`leadingDispatch`和`trailingDispatch`函数合并为`dispatcher`函数,根据传入的类型判断执行逻辑
- 优化了`watch`回调函数,使用`dispatcher`函数替代重复的判断逻辑

* feat: 写法优化

* feat: 引入`isObject`函数替代原有的`typeof throttle === 'object'`判断方式

* feat: 优化骨架屏文档结构和示例

* feat: 完善文字描述和修改对应的文件名

* Update docs/en-US/component/skeleton.md

Co-authored-by: btea <2356281422@qq.com>

* Update docs/en-US/component/skeleton.md

Co-authored-by: btea <2356281422@qq.com>

* feat: Optimize code writing

* Update docs/en-US/component/skeleton.md

Co-authored-by: btea <2356281422@qq.com>

* Update docs/en-US/component/skeleton.md

* feat: modify doc

* feat: md

* feat: 补充 useThrottleRender 钩子的测试用例

* feat: 将 SkeletonThrottle 类型移动到hook中, 重命名为 ThrottleType 以提高通用性

---------

Co-authored-by: btea <2356281422@qq.com>
2024-11-07 21:31:16 +08:00

6.9 KiB

title, lang
title lang
Skeleton en-US

Skeleton

When loading data, and you need a rich experience for visual and interactions for your end users, you can choose skeleton.

Basic usage

The basic skeleton.

:::demo

skeleton/basic-usage

:::

Configurable Rows

You can configure the row numbers yourself, for more precise rendering effect, the actual rendered row number will always be 1 row more than the given number, that is because we are rendering a title row with 33% width of the others.

:::demo

skeleton/configurable-rows

:::

Animation

We have provided a switch flag indicating whether showing the loading animation, called animated when this is true, all children of el-skeleton will show animation

:::demo

skeleton/animation

:::

Customized Template

Element Plus only provides the most common template, sometimes that could be a problem, so you have a slot named template to do that work.

Also we have provided different types skeleton unit that you can choose, for more detailed info, please scroll down to the bottom of this page to see the API description. Also, when building your own customized skeleton structure, you should be structuring them as closer to the real DOM as possible, which avoiding the DOM bouncing caused by the height difference.

:::demo

skeleton/customized-template

:::

Loading state

When Loading ends, we always need to show the real UI with data to our end users. with the attribute loading we can control whether showing the DOM. You can also use slot default to structure the real DOM element.

:::demo

skeleton/loading-state

:::

Rendering a list of data

Most of the time, skeleton is used as indicators of rendering a list of data which haven't been fetched from server yet, then we need to create a list of skeleton out of no where to make it look like it is loading, with count attribute, you can control how many these templates you need to render to the browser.

:::tip

We do not recommend rendering lots of fake UI to the browser, it will still cause the performance issue, it also costs longer to destroy the skeleton. Keep count as small as it can be to make better user experience.

:::

:::demo

skeleton/rendering-with-data

:::

Avoiding rendering bouncing.

Sometimes API responds very quickly, when that happens, the skeleton just gets rendered to the DOM then it needs to switch back to real DOM, that causes the sudden flashy. To avoid such thing, you can use the throttle attribute.

:::tip

Since ^(2.8.8), the throttle attribute supports two values: number and object. When passing a number, it is equivalent to {leading: xxx}, controlling the throttling of the skeleton screen display. Of course, you can also control the throttling of the skeleton screen disappearance by passing {trailing: xxx}

:::

:::demo

skeleton/avoiding-rendering-bouncing

:::

Initial rendering loading ^(2.8.8)

When the initial value of loading is true, you can set throttle: {initVal: true, leading: xxx} to control the immediate display of the initial skeleton screen without throttling.

:::demo

skeleton/initial-rendering-loading

:::

Toggle show/hide without rending bouncing ^(2.8.8)

:::tip

You can set throttle: {initVal: true, leading: xxx, trailing: xxx} to control the initial display of the skeleton effect and to make the transition of the skeleton more smooth when switching loading states.

:::

Sometimes you want to render the business components more smoothly when loading toggle show or hide. You can use set the throttle: {leading: xxx, trailing:xxx} to control the rendering bouncing.

:::demo

skeleton/leading-trailing-without-bouncing

:::

Skeleton API

Skeleton Attributes

Name Description Type Default
animated whether showing the animation ^[boolean] false
count how many fake items to render to the DOM ^[number] 1
loading whether showing the real DOM ^[boolean] false
rows numbers of the row, only useful when no template slot were given ^[number] 3
throttle rendering delay in milliseconds. Numbers represent delayed display, and can also be set to delay hide, for example { leading: 500, trailing: 500 }. When needing to control the initial value of loading, you can set { initVal: true } ^[number] / ^[object]{ leading?: number, trailing?: number, initVal?: boolean } 0

Skeleton Slots

Name Description Scope
default real rendering DOM ^[object]$attrs
template content as rendering skeleton template ^[object]{ key: number }

SkeletonItem API

SkeletonItem Attributes

Name Description Type Default
variant the current rendering skeleton type ^[enum]'p' | 'text' | 'h1' | 'h3' | 'caption' | 'button' | 'image' | 'circle' | 'rect' text