From ae38e7eab04dd5863a26a69139db4e9af237d2f2 Mon Sep 17 00:00:00 2001 From: Ljs Date: Fri, 21 May 2021 15:41:11 +0800 Subject: [PATCH] add item slot --- src/index.js | 2 ++ src/item.js | 4 ++-- src/props.js | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index de144c6..5f8581e 100644 --- a/src/index.js +++ b/src/index.js @@ -271,6 +271,7 @@ const VirtualList = Vue.component('virtual-list', { const slots = [] const { start, end } = this.range const { dataSources, dataKey, itemClass, itemTag, itemStyle, isHorizontal, extraProps, dataComponent, itemScopedSlots } = this + const slotComponent = this.$scopedSlots && this.$scopedSlots.item for (let index = start; index <= end; index++) { const dataSource = dataSources[index] if (dataSource) { @@ -286,6 +287,7 @@ const VirtualList = Vue.component('virtual-list', { source: dataSource, extraProps: extraProps, component: dataComponent, + slotComponent: slotComponent, scopedSlots: itemScopedSlots }, style: itemStyle, diff --git a/src/item.js b/src/item.js index 6aba187..a10804a 100644 --- a/src/item.js +++ b/src/item.js @@ -51,7 +51,7 @@ export const Item = Vue.component('virtual-list-item', { props: ItemProps, render (h) { - const { tag, component, extraProps = {}, index, source, scopedSlots = {}, uniqueKey } = this; + const { tag, component, extraProps = {}, index, source, scopedSlots = {}, uniqueKey, slotComponent } = this; const props = { ...extraProps, source, @@ -63,7 +63,7 @@ export const Item = Vue.component('virtual-list-item', { attrs: { role: 'listitem' } - }, [h(component, { + }, [slotComponent ? h('div', slotComponent({ item: source, index: index, scope: props })) : h(component, { props, scopedSlots: scopedSlots })]) diff --git a/src/props.js b/src/props.js index 95b6879..a1634ef 100644 --- a/src/props.js +++ b/src/props.js @@ -127,6 +127,9 @@ export const ItemProps = { component: { type: [Object, Function] }, + slotComponent: { + type: Function + }, uniqueKey: { type: [String, Number] },