You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-26Lines changed: 46 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ There are several components provided by `vue-virtual-scroller`:
99
99
100
100
[RecycleScroller](#recyclescroller) is a component that only renders the visible item in your list. It also re-use components and dom elements to be the most efficient and performant possible.
101
101
102
-
[DynamicScroller](#dynamicscroller) is a component is using RecycleScroller under-the-hood and adds a dynamic height management feature on top of it. The main use case for this is **not knowing the height of the items** in advance: the Dynamic Scroller will automatically "discover" it when it renders new item as the user scrolls.
102
+
[DynamicScroller](#dynamicscroller) is a component is using RecycleScroller under-the-hood and adds a dynamic size management feature on top of it. The main use case for this is **not knowing the size of the items** in advance: the Dynamic Scroller will automatically "discover" it when it renders new item as the user scrolls.
103
103
104
104
[DynamicScrollerItem](#dynamicscrolleritem) must wrap each item in a DynamicScroller to handle size computations.
105
105
@@ -118,9 +118,10 @@ Use the scoped slot to render each item in the list:
118
118
<RecycleScroller
119
119
class="scroller"
120
120
:items="list"
121
-
:item-height="32"
121
+
:item-size="32"
122
+
key-field="id"
122
123
>
123
-
<divslot-scope="{ item }"class="user">
124
+
<divv-slot="{ item }"class="user">
124
125
{{ item.name }}
125
126
</div>
126
127
</RecycleScroller>
@@ -150,12 +151,12 @@ export default {
150
151
151
152
### Important notes
152
153
153
-
- ⚠️ You need to set the size of the virtual-scroller element and the items elements (for example, with CSS). Unless you are using [variable height mode](#variable-height-mode), all items should have the same height to prevent display glitches.
154
-
- If the items are objects, the scroller needs to be able to identify them. By default it will look for an `id` field on the items. This can be configured with the `keyField` prop.
154
+
-**⚠️ You need to set the size of the virtual-scroller element and the items elements (for example, with CSS). Unless you are using [variable size mode](#variable-size-mode), all items should have the same height (or width in horizontal mode) to prevent display glitches.**
155
+
-**⚠️ If the items are objects, the scroller needs to be able to identify them. By default it will look for an `id` field on the items. This can be configured with the `keyField` prop if you are using another field name.**
155
156
- It is not recommended to use functional components inside RecycleScroller since the components are reused (so it will actually be slower).
156
157
- The components used in the list should expect `item` prop change without being re-created (use computed props or watchers to properly react to props changes!).
157
158
- You don't need to set `key` on list content (but you should on all nested `<img>` elements to prevent load glitches).
158
-
- The browsers have a height limitation on DOM elements, it means that currently the virtual scroller can't display more than ~500k items depending on the browser.
159
+
- The browsers have a size limitation on DOM elements, it means that currently the virtual scroller can't display more than ~500k items depending on the browser.
159
160
- Since DOM elements are reused for items, it's recommended to define hover styles using the provided `hover` class instead of the `:hover` state selector (e.g. `.vue-recycle-scroller__item-view.hover` or `.hover .some-element-inside-the-item-view`).
160
161
161
162
### How does it work?
@@ -165,7 +166,7 @@ export default {
165
166
- For each type of item, a new pool is created so that the same components (and DOM trees) are reused for the same type.
166
167
- Views can be deactivated if they go off-screen, and can be reused anytime for a newly visible item.
167
168
168
-
Here is what the internals of RecycleScroller look like:
169
+
Here is what the internals of RecycleScroller look like in vertical mode:
169
170
170
171
```html
171
172
<RecycleScroller>
@@ -194,9 +195,10 @@ When the user scrolls inside RecycleScroller, the views are mostly just moved ar
194
195
### Props
195
196
196
197
-`items`: list of items you want to display in the scroller.
197
-
-`itemHeight` (default: `null`): display height of the items in pixels used to calculate the scroll height and position. If it set to `null` (the default value), it will use [variable height mode](#variable-height-mode).
198
-
-`minItemHeight`: minimum height used if the height of a item is unknown.
199
-
-`heightField` (default: `'height'`): field used to get the item's height in variable height mode.
198
+
-`direction` (default: `'vertical'`): scrolling direction, either `'vertical'` or `'horizontal'`.
199
+
-`itemSize` (default: `null`): display height (or width in horizontal mode) of the items in pixels used to calculate the scroll size and position. If it set to `null` (the default value), it will use [variable size mode](#variable-size-mode).
200
+
-`minItemSize`: minimum size used if the height (or width in horizontal mode) of a item is unknown.
201
+
-`sizeField` (default: `'size'`): field used to get the item's size in variable size mode.
200
202
-`typeField` (default: `'type'`): field used to differenciate different kinds of components in the list. For each distinct type, a pool of recycled items will be created.
201
203
-`keyField` (default: `'id'`): field used to identify items and optimize render views management.
@@ -221,14 +223,32 @@ When the user scrolls inside RecycleScroller, the views are mostly just moved ar
221
223
222
224
```html
223
225
<main>
224
-
<slotname="before-container"></slot>
226
+
<slotname="before"></slot>
225
227
<wrapper>
226
228
<!-- Reused view pools here -->
227
229
</wrapper>
228
-
<slotname="after-container"></slot>
230
+
<slotname="after"></slot>
229
231
</main>
230
232
```
231
233
234
+
Example:
235
+
236
+
```html
237
+
<RecycleScroller
238
+
class="scroller"
239
+
:items="list"
240
+
:item-size="32"
241
+
>
242
+
<template#before>
243
+
Hey! I'm a message displayed before the items!
244
+
</template>
245
+
246
+
<divv-slot="{ item }"class="user">
247
+
{{ item.name }}
248
+
</div>
249
+
</RecycleScroller>
250
+
```
251
+
232
252
### Page mode
233
253
234
254
The page mode expand the virtual-scroller and use the page viewport to compute which items are visible. That way, you can use it in a big page with HTML elements before or after (like a header and a footer). Just set the `page-mode` props to `true`:
@@ -247,15 +267,15 @@ The page mode expand the virtual-scroller and use the page viewport to compute w
247
267
</footer>
248
268
```
249
269
250
-
### Variable height mode
270
+
### Variable size mode
251
271
252
272
**⚠️ This mode can be performance heavy with a lot of items. Use with caution.**
253
273
254
-
If the `itemHeight` prop is not set or set to `null`, the virtual scroller will switch to Variable height mode. You then need to expose a number field on the item objects with the height of the item element.
274
+
If the `itemSize` prop is not set or set to `null`, the virtual scroller will switch to Variable size mode. You then need to expose a number field on the item objects with the size of the item element.
255
275
256
-
**⚠️ You still need to set the height of the items with CSS correctly (with classes for example).**
276
+
**⚠️ You still need to set the size of the items with CSS correctly (with classes for example).**
257
277
258
-
Use the `heightField` prop (default is `'height'`) to set the field used by the scroller to get the height for each item.
278
+
Use the `sizeField` prop (default is `'size'`) to set the field used by the scroller to get the size for each item.
259
279
260
280
Example:
261
281
@@ -264,17 +284,17 @@ const items = [
264
284
{
265
285
id:1,
266
286
label:'Title',
267
-
height:64,
287
+
size:64,
268
288
},
269
289
{
270
290
id:2,
271
291
label:'Foo',
272
-
height:32,
292
+
size:32,
273
293
},
274
294
{
275
295
id:3,
276
296
label:'Bar',
277
-
height:32,
297
+
size:32,
278
298
},
279
299
]
280
300
```
@@ -296,25 +316,25 @@ The `prerender` props can be set as the number of items to render on the server
296
316
```html
297
317
<RecycleScroller
298
318
:items="items"
299
-
:item-height="42"
319
+
:item-size="42"
300
320
:prerender="10"
301
321
>
302
322
```
303
323
304
324
## DynamicScroller
305
325
306
-
This works like RecycleScroller but can render items with unknown heights!
326
+
This works like RecycleScroller but can render items with unknown sizes!
307
327
308
328
### Basic usage
309
329
310
330
```html
311
331
<template>
312
332
<DynamicScroller
313
333
:items="items"
314
-
:min-item-height="54"
334
+
:min-item-size="54"
315
335
class="scroller"
316
336
>
317
-
<templateslot-scope="{ item, index, active }">
337
+
<templatev-slot="{ item, index, active }">
318
338
<DynamicScrollerItem
319
339
:item="item"
320
340
:active="active"
@@ -354,15 +374,15 @@ export default {
354
374
355
375
### Important notes
356
376
357
-
-`minItemHeight` is required for the initial render of items.
377
+
-`minItemSize` is required for the initial render of items.
358
378
-`DynamicScroller` won't detect size changes on its own, but you can put values that can affect the item size with `size-dependencies` on [DynamicScrollerItem](#dynamicscrolleritem).
359
-
- You don't need to have a `height` field on the items.
379
+
- You don't need to have a `size` field on the items.
360
380
361
381
### Props
362
382
363
383
All the RecycleScroller props.
364
384
365
-
- It's not recommended to change `heightField` prop since all the height management is done internally.
385
+
- It's not recommended to change `sizeField` prop since all the size management is done internally.
0 commit comments