Skip to content

Commit df19ba0

Browse files
tibineaguGuillaume Chau
authored andcommitted
Add index to scoped props available in RecycleList (#54)
* Added the item's index in the list as a scoped property for RecycleList slots * Adjusted demo page to show usage of the index scoped property * Added new index scoped prop to readme
1 parent 51ec54d commit df19ba0

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ It's very similar to virtual-scroller, but:
358358
- Recycles scoped slot content (including components) in the list (no destroyed components), depending on item types (customize with `typeField` prop)
359359
- 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!)
360360
- You don't need to set `key` on list content (but you should on `<img>` elements)
361+
- To emulate conditions that would otherwise be available in a `v-for` loop, the scoped slot exposes an `index` prop that reflects each item's position in the `items` array
361362

362363
Both fixed and dynamic height modes are supported (set `itemHeight` prop for fixed height mode).
363364

@@ -367,7 +368,7 @@ Both fixed and dynamic height modes are supported (set `itemHeight` prop for fix
367368
:items="items"
368369
>
369370
<!-- For each item -->
370-
<template slot-scope="{ item }">
371+
<template slot-scope="{ item, index }">
371372
<!-- Reactive dynamic height -->
372373
<div
373374
v-if="item.type === 'letter'"
@@ -381,6 +382,7 @@ Both fixed and dynamic height modes are supported (set `itemHeight` prop for fix
381382
<MyPersonComponent
382383
v-else-if="item.type === 'person'"
383384
:data="item.value"
385+
:index="index"
384386
/>
385387
</template>
386388
</recycle-list>

docs-src/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@
8989
@click="props.item.height = (props.item.height === 200 ? 300 : 200)"
9090
>
9191
<td class="index">
92-
{{props.item.index}}
92+
{{props.index}}
9393
</td>
9494
<td class="value">
9595
{{props.item.value}} Scoped
9696
</td>
9797
</tr>
98-
<item v-if="props.item.type === 'person'" :item="props.item"></item>
98+
<item v-if="props.item.type === 'person'" :item="props.item" :index="props.index"></item>
9999
</template>
100100
</recycle-list>
101101
</template>

docs-src/src/Item.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<tr class="person" @click="edit">
33
<td class="index">
4-
{{item.index}}
4+
{{index}}
55
</td>
66
<td>
77
<div class="info">
@@ -18,7 +18,7 @@
1818

1919
<script>
2020
export default {
21-
props: ['item'],
21+
props: ['item', 'index'],
2222
2323
created () {
2424
console.log('created')

src/components/RecycleList.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
>
1919
<slot
2020
:item="view.item"
21+
:index="view.nr.index"
2122
:active="view.nr.used"
2223
/>
2324
</div>

0 commit comments

Comments
 (0)