Skip to content

Commit 23fcd7c

Browse files
Ljstangbc
Ljs
authored andcommitted
add item slot
1 parent a39fca7 commit 23fcd7c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ const VirtualList = Vue.component('virtual-list', {
271271
const slots = []
272272
const { start, end } = this.range
273273
const { dataSources, dataKey, itemClass, itemTag, itemStyle, isHorizontal, extraProps, dataComponent, itemScopedSlots } = this
274+
const slotComponent = this.$scopedSlots && this.$scopedSlots.item
274275
for (let index = start; index <= end; index++) {
275276
const dataSource = dataSources[index]
276277
if (dataSource) {
@@ -286,6 +287,7 @@ const VirtualList = Vue.component('virtual-list', {
286287
source: dataSource,
287288
extraProps: extraProps,
288289
component: dataComponent,
290+
slotComponent: slotComponent,
289291
scopedSlots: itemScopedSlots
290292
},
291293
style: itemStyle,

src/item.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const Item = Vue.component('virtual-list-item', {
5151
props: ItemProps,
5252

5353
render (h) {
54-
const { tag, component, extraProps = {}, index, source, scopedSlots = {}, uniqueKey } = this;
54+
const { tag, component, extraProps = {}, index, source, scopedSlots = {}, uniqueKey, slotComponent } = this;
5555
const props = {
5656
...extraProps,
5757
source,
@@ -63,7 +63,7 @@ export const Item = Vue.component('virtual-list-item', {
6363
attrs: {
6464
role: 'listitem'
6565
}
66-
}, [h(component, {
66+
}, [slotComponent ? h('div', slotComponent({ item: source, index: index, scope: props })) : h(component, {
6767
props,
6868
scopedSlots: scopedSlots
6969
})])

src/props.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export const ItemProps = {
127127
component: {
128128
type: [Object, Function]
129129
},
130+
slotComponent: {
131+
type: Function
132+
},
130133
uniqueKey: {
131134
type: [String, Number]
132135
},

0 commit comments

Comments
 (0)