mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(List): add en FAQ (#10508)
This commit is contained in:
parent
1df47afc17
commit
c17281f9c2
packages/vant/src/list
@ -231,3 +231,62 @@ The component provides the following CSS variables, which can be used to customi
|
||||
| --van-list-text-font-size | _var(--van-font-size-md)_ | - |
|
||||
| --van-list-text-line-height | _50px_ | - |
|
||||
| --van-list-loading-icon-size | _16px_ | - |
|
||||
|
||||
## FAQ
|
||||
|
||||
### How does List component work?
|
||||
|
||||
List will listen to the scroll event of the browser and calculate the position. When the distance between the bottom of the list and the visible area is less than `offset`, the List component will trigger a `load` event.
|
||||
|
||||
### Why does the load event triggered immediately after mounted?
|
||||
|
||||
A load event will be triggered immediately to load the first screen data. This feature can be disabled by the `immediate-check` prop.
|
||||
|
||||
### Why does the load event triggered continuously?
|
||||
|
||||
If the amount of data loaded in one request is too small, the List will continue to trigger the `load` event until the content fills the screen or the data is fully loaded.
|
||||
|
||||
Therefore, you need to adjust the amount of data per request. Ideally, the amount of data per request should be able to fill the height of one screen.
|
||||
|
||||
### What is the meaning of loading and finished?
|
||||
|
||||
`List` has three states, understanding these states will help you use the component:
|
||||
|
||||
- `loading = false`: Not in loading. The component will detect whether to trigger the `load` event according to the scroll position (if the content of the list is less than one screen, it will be triggered directly).
|
||||
- `loading = true`: During loading. Indicating that an request is being sent, and the `load` event will not be triggered.
|
||||
- `finished = true`: Loading is complete. No `load` will not be triggered.
|
||||
|
||||
After each request, you need to manually set `loading` to `false`, indicating the end of loading.
|
||||
|
||||
### Always trigger loading after using float layout?
|
||||
|
||||
If you use the float layout on the content, you can add the `van-clearfix` class to the container to clear the float, so that the List can get the element position correctly.
|
||||
|
||||
```html
|
||||
<van-list>
|
||||
<div class="van-clearfix">
|
||||
<div class="float-item" />
|
||||
<div class="float-item" />
|
||||
<div class="float-item" />
|
||||
</div>
|
||||
</van-list>
|
||||
```
|
||||
|
||||
### Always trigger loading after setting overflow on html and body?
|
||||
|
||||
If the `overflow-x: hidden` style is set on the html and body tags, it will cause the List to always trigger loading.
|
||||
|
||||
```css
|
||||
html,
|
||||
body {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
```
|
||||
|
||||
The reason is that when an element is styled with `overflow-x: hidden`, the element's `overflow-y` will be set to `auto` by the browser, instead of the default value of `visible`, causing the List can not determine the scroll container correctly. The workaround is to remove this style, or add the `height: 100%` style to the html and body tags.
|
||||
|
||||
### Always trigger loading when the direction prop is set to up?
|
||||
|
||||
Setting the `direction` prop to up will trigger the loading of the List component when the scrollbar is at the page top.
|
||||
|
||||
When using this prop, it is recommended to scroll the scroll bar to the page bottom after each data request is completed.
|
||||
|
@ -251,7 +251,7 @@ listRef.value?.check();
|
||||
|
||||
### List 的运行机制是什么?
|
||||
|
||||
List 会监听浏览器的滚动事件并计算列表的位置,当列表底部与可视区域的距离小于 `offset` 时,List 会触发一次 load 事件。
|
||||
List 会监听浏览器的滚动事件并计算列表的位置,当列表底部与可视区域的距离小于 `offset` 时,List 会触发一次 `load` 事件。
|
||||
|
||||
### 为什么 List 初始化后会立即触发 load 事件?
|
||||
|
||||
@ -259,21 +259,23 @@ List 初始化后会触发一次 load 事件,用于加载第一屏的数据,
|
||||
|
||||
### 为什么会连续触发 load 事件?
|
||||
|
||||
如果一次请求加载的数据条数较少,导致列表内容无法铺满当前屏幕,List 会继续触发 load 事件,直到内容铺满屏幕或数据全部加载完成。因此你需要调整每次获取的数据条数,理想情况下每次请求获取的数据条数应能够填满一屏高度。
|
||||
如果一次请求加载的数据条数较少,导致列表内容无法铺满当前屏幕,List 会继续触发 `load` 事件,直到内容铺满屏幕或数据全部加载完成。
|
||||
|
||||
因此你需要调整每次获取的数据条数,理想情况下每次请求获取的数据条数应能够填满一屏高度。
|
||||
|
||||
### loading 和 finished 分别是什么含义?
|
||||
|
||||
`List` 有以下三种状态,理解这些状态有助于你正确地使用 `List` 组件:
|
||||
|
||||
- 非加载中,`loading` 为 `false`,此时会根据列表滚动位置判断是否触发 `load` 事件(列表内容不足一屏幕时,会直接触发)
|
||||
- 加载中,`loading` 为 `true`,表示正在发送异步请求,此时不会触发 `load` 事件
|
||||
- 加载完成,`finished` 为 `true`,此时不会触发 `load` 事件
|
||||
- 非加载中,`loading` 为 `false`,此时会根据列表滚动位置判断是否触发 `load` 事件(列表内容不足一屏幕时,会直接触发)。
|
||||
- 加载中,`loading` 为 `true`,表示正在发送异步请求,此时不会触发 `load` 事件。
|
||||
- 加载完成,`finished` 为 `true`,此时不会触发 `load` 事件。
|
||||
|
||||
在每次请求完毕后,需要手动将 `loading` 设置为 `false`,表示加载结束
|
||||
在每次请求完毕后,需要手动将 `loading` 设置为 `false`,表示加载结束。
|
||||
|
||||
### 使用 float 布局后一直触发加载?
|
||||
|
||||
若 List 的内容使用了 float 布局,可以在容器上添加 `van-clearfix` 类名来清除浮动,使得 List 能正确判断元素位置
|
||||
若 List 的内容使用了 float 布局,可以在容器上添加 `van-clearfix` 类名来清除浮动,使得 List 能正确判断元素位置。
|
||||
|
||||
```html
|
||||
<van-list>
|
||||
|
Loading…
x
Reference in New Issue
Block a user