Skip to content

Commit

Permalink
Fixed start and offset prop data change reactive #188
Browse files Browse the repository at this point in the history
  • Loading branch information
tangbc committed Apr 22, 2020
1 parent c0f6423 commit 427bdff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
47 changes: 27 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-virtual-scroll-list v2.0.8
* vue-virtual-scroll-list v2.0.9
* open source under the MIT license
* https://github.com/tangbc/vue-virtual-scroll-list#readme
*/
Expand Down Expand Up @@ -113,7 +113,7 @@
}, {
key: "getOffset",
value: function getOffset(start) {
return this.getIndexOffset(start);
return start < 1 ? 0 : this.getIndexOffset(start);
}
}, {
key: "updateParam",
Expand Down Expand Up @@ -581,6 +581,12 @@
this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources());
this.virtual.handleDataSourcesChange();
}
},
start: function start(newValue) {
this.scrollToIndex(newValue);
},
offset: function offset(newValue) {
this.scrollToOffset(newValue);
}
},
created: function created() {
Expand Down Expand Up @@ -620,11 +626,8 @@
},
// set current scroll position to a expectant index
scrollToIndex: function scrollToIndex(index) {
// scroll to top
if (index <= 0) {
this.scrollToOffset(0);
} else if (index >= this.dataSources.length - 1) {
// scroll to bottom
// scroll to bottom
if (index >= this.dataSources.length - 1) {
this.scrollToBottom();
} else {
var offset = this.virtual.getOffset(index);
Expand Down Expand Up @@ -748,20 +751,24 @@
var dataSource = this.dataSources[index];

if (dataSource) {
slots.push(h(Item, {
"class": this.itemClass,
props: {
tag: this.itemTag,
event: EVENT_TYPE.ITEM,
horizontal: this.isHorizontal,
uniqueKey: dataSource[this.dataKey],
source: dataSource,
extraProps: this.extraProps,
component: this.dataComponent
}
}));
if (dataSource[this.dataKey]) {
slots.push(h(Item, {
"class": this.itemClass,
props: {
tag: this.itemTag,
event: EVENT_TYPE.ITEM,
horizontal: this.isHorizontal,
uniqueKey: dataSource[this.dataKey],
source: dataSource,
extraProps: this.extraProps,
component: this.dataComponent
}
}));
} else {
console.warn("Cannot get the data-key '".concat(this.dataKey, "' from data-sources."));
}
} else {
console.warn("Cannot get the index ".concat(index, " from data-sources."));
console.warn("Cannot get the index '".concat(index, "' from data-sources."));
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-virtual-scroll-list",
"version": "2.0.8",
"version": "2.0.9",
"description": "A vue component support big amount data list with high scroll performance.",
"main": "dist/index.js",
"files": [
Expand Down
15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const VirtualList = Vue.component('virtual-list', {
this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources())
this.virtual.handleDataSourcesChange()
}
},

start (newValue) {
this.scrollToIndex(newValue)
},

offset (newValue) {
this.scrollToOffset(newValue)
}
},

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

// set current scroll position to a expectant index
scrollToIndex (index) {
// scroll to top
if (index <= 0) {
this.scrollToOffset(0)
} else if (index >= this.dataSources.length - 1) {
// scroll to bottom
// scroll to bottom
if (index >= this.dataSources.length - 1) {
this.scrollToBottom()
} else {
const offset = this.virtual.getOffset(index)
Expand Down
2 changes: 1 addition & 1 deletion src/virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class Virtual {

// return start index offset
getOffset (start) {
return this.getIndexOffset(start)
return start < 1 ? 0 : this.getIndexOffset(start)
}

updateParam (key, value) {
Expand Down

0 comments on commit 427bdff

Please sign in to comment.