Skip to content

Commit 427bdff

Browse files
committed
Fixed start and offset prop data change reactive #188
1 parent c0f6423 commit 427bdff

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

dist/index.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-virtual-scroll-list v2.0.8
2+
* vue-virtual-scroll-list v2.0.9
33
* open source under the MIT license
44
* https://github.com/tangbc/vue-virtual-scroll-list#readme
55
*/
@@ -113,7 +113,7 @@
113113
}, {
114114
key: "getOffset",
115115
value: function getOffset(start) {
116-
return this.getIndexOffset(start);
116+
return start < 1 ? 0 : this.getIndexOffset(start);
117117
}
118118
}, {
119119
key: "updateParam",
@@ -581,6 +581,12 @@
581581
this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources());
582582
this.virtual.handleDataSourcesChange();
583583
}
584+
},
585+
start: function start(newValue) {
586+
this.scrollToIndex(newValue);
587+
},
588+
offset: function offset(newValue) {
589+
this.scrollToOffset(newValue);
584590
}
585591
},
586592
created: function created() {
@@ -620,11 +626,8 @@
620626
},
621627
// set current scroll position to a expectant index
622628
scrollToIndex: function scrollToIndex(index) {
623-
// scroll to top
624-
if (index <= 0) {
625-
this.scrollToOffset(0);
626-
} else if (index >= this.dataSources.length - 1) {
627-
// scroll to bottom
629+
// scroll to bottom
630+
if (index >= this.dataSources.length - 1) {
628631
this.scrollToBottom();
629632
} else {
630633
var offset = this.virtual.getOffset(index);
@@ -748,20 +751,24 @@
748751
var dataSource = this.dataSources[index];
749752

750753
if (dataSource) {
751-
slots.push(h(Item, {
752-
"class": this.itemClass,
753-
props: {
754-
tag: this.itemTag,
755-
event: EVENT_TYPE.ITEM,
756-
horizontal: this.isHorizontal,
757-
uniqueKey: dataSource[this.dataKey],
758-
source: dataSource,
759-
extraProps: this.extraProps,
760-
component: this.dataComponent
761-
}
762-
}));
754+
if (dataSource[this.dataKey]) {
755+
slots.push(h(Item, {
756+
"class": this.itemClass,
757+
props: {
758+
tag: this.itemTag,
759+
event: EVENT_TYPE.ITEM,
760+
horizontal: this.isHorizontal,
761+
uniqueKey: dataSource[this.dataKey],
762+
source: dataSource,
763+
extraProps: this.extraProps,
764+
component: this.dataComponent
765+
}
766+
}));
767+
} else {
768+
console.warn("Cannot get the data-key '".concat(this.dataKey, "' from data-sources."));
769+
}
763770
} else {
764-
console.warn("Cannot get the index ".concat(index, " from data-sources."));
771+
console.warn("Cannot get the index '".concat(index, "' from data-sources."));
765772
}
766773
}
767774

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-virtual-scroll-list",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"description": "A vue component support big amount data list with high scroll performance.",
55
"main": "dist/index.js",
66
"files": [

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ const VirtualList = Vue.component('virtual-list', {
3131
this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources())
3232
this.virtual.handleDataSourcesChange()
3333
}
34+
},
35+
36+
start (newValue) {
37+
this.scrollToIndex(newValue)
38+
},
39+
40+
offset (newValue) {
41+
this.scrollToOffset(newValue)
3442
}
3543
},
3644

@@ -78,11 +86,8 @@ const VirtualList = Vue.component('virtual-list', {
7886

7987
// set current scroll position to a expectant index
8088
scrollToIndex (index) {
81-
// scroll to top
82-
if (index <= 0) {
83-
this.scrollToOffset(0)
84-
} else if (index >= this.dataSources.length - 1) {
85-
// scroll to bottom
89+
// scroll to bottom
90+
if (index >= this.dataSources.length - 1) {
8691
this.scrollToBottom()
8792
} else {
8893
const offset = this.virtual.getOffset(index)

src/virtual.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class Virtual {
7070

7171
// return start index offset
7272
getOffset (start) {
73-
return this.getIndexOffset(start)
73+
return start < 1 ? 0 : this.getIndexOffset(start)
7474
}
7575

7676
updateParam (key, value) {

0 commit comments

Comments
 (0)