Skip to content

Commit 76b8ac1

Browse files
committed
itemKey for scoped slots, perf notes in Readme
1 parent 4c5ee8d commit 76b8ac1

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

Diff for: README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ There are additional props you can use:
127127
- `typeField` to customize which field is used on the items to get their type and use the corresponding definition in the `renderers` map. The default is `'type'`.
128128
- `keyField` to customize which field is used on the items to set their `key` special attribute (see [the documation](https://vuejs.org/v2/api/#key)). The default is `'id'`.
129129

130+
**For better performance, you should use the `keyField` prop that whill set the `key` attribute. Warning! You shouldn't expect items to have the key set at all times, since the scroller may disable them depending on the situation.**
131+
130132
## Scoped slots
131133

132134
Alternatively, you can use [scoped slots](https://vuejs.org/v2/guide/components.html#Scoped-Slots) instead of `renderers`. This is active when you don't define the `renderers` prop on the virtual scroller.
@@ -138,13 +140,13 @@ Here is an example:
138140
```html
139141
<virtual-scroller class="scroller" :items="items" item-height="42" content-tag="table">
140142
<template scope="props">
141-
<tr v-if="props.item.type === 'letter'" class="letter">
143+
<tr v-if="props.item.type === 'letter'" class="letter" :key="props.itemKey">
142144
<td>
143145
{{props.item.value}} Scoped
144146
</td>
145147
</tr>
146148

147-
<tr v-if="props.item.type === 'person'" class="person">
149+
<tr v-if="props.item.type === 'person'" class="person" :key="props.itemKey">
148150
<td>
149151
{{props.item.value.name}}
150152
</td>
@@ -153,6 +155,8 @@ Here is an example:
153155
</virtual-scroller>
154156
```
155157

158+
**For better performance, you should set the `key` attribute on direct children using the `itemKey` field from the scoped slot and set the `keyField` prop on the virtual scroller.**
159+
156160
## Page mode
157161

158162
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`:

Diff for: dist/vue-virtual-scroller.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-virtual-scroller",
33
"description": "Smooth scrolling for any amount of data",
4-
"version": "0.5.0",
4+
"version": "0.5.1",
55
"author": {
66
"name": "Guillaume Chau",
77
"email": "[email protected]"

Diff for: src/components/VirtualScroller.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<component class="item" v-for="item in visibleItems" :key="keysEnabled && item[keyField]" :is="renderers[item[typeField]]" :item="item"></component>
77
</template>
88
<template v-else>
9-
<slot class="item" v-for="item in visibleItems" :item="item"></slot>
9+
<slot class="item" v-for="item in visibleItems" :item="item" :item-key="keysEnabled && item[keyField]"></slot>
1010
</template>
1111
</component>
1212
</component>

0 commit comments

Comments
 (0)