Skip to content

Commit c0f6423

Browse files
committed
Warning when data-key error
1 parent 5608548 commit c0f6423

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,24 @@ const VirtualList = Vue.component('virtual-list', {
211211
for (let index = start; index <= end; index++) {
212212
const dataSource = this.dataSources[index]
213213
if (dataSource) {
214-
slots.push(h(Item, {
215-
class: this.itemClass,
216-
props: {
217-
tag: this.itemTag,
218-
event: EVENT_TYPE.ITEM,
219-
horizontal: this.isHorizontal,
220-
uniqueKey: dataSource[this.dataKey],
221-
source: dataSource,
222-
extraProps: this.extraProps,
223-
component: this.dataComponent
224-
}
225-
}))
214+
if (dataSource[this.dataKey]) {
215+
slots.push(h(Item, {
216+
class: this.itemClass,
217+
props: {
218+
tag: this.itemTag,
219+
event: EVENT_TYPE.ITEM,
220+
horizontal: this.isHorizontal,
221+
uniqueKey: dataSource[this.dataKey],
222+
source: dataSource,
223+
extraProps: this.extraProps,
224+
component: this.dataComponent
225+
}
226+
}))
227+
} else {
228+
console.warn(`Cannot get the data-key '${this.dataKey}' from data-sources.`)
229+
}
226230
} else {
227-
console.warn(`Cannot get the index ${index} from data-sources.`)
231+
console.warn(`Cannot get the index '${index}' from data-sources.`)
228232
}
229233
}
230234
return slots

0 commit comments

Comments
 (0)