Skip to content

Commit 58afa0b

Browse files
committed
Merge branch 'master' into chat-app
2 parents 7ac6bbc + b33b81e commit 58afa0b

File tree

10 files changed

+45
-33
lines changed

10 files changed

+45
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
## Advantages
3636

37-
* Tiny, simple and very very easy to use.
37+
* Tiny, simple structure and very easy to use.
3838

3939
* Big data list with high render performance and efficient.
4040

@@ -131,7 +131,7 @@ More usages or getting start you can refer to these clearly [examples](https://g
131131

132132
### Optional props
133133

134-
<details>
134+
<details open>
135135
<summary><strong>Commonly used</strong></summary>
136136
<p></p>
137137
<table>

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

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><title>vue-virtual-scroll-list</title><link rel=icon href=favicon.png><link rel=stylesheet href=milligram.css><link rel=stylesheet href=highlight/theme.css><script src=highlight/pack.js></script><script>hljs.initHighlightingOnLoad()</script><link href=css/dynamic-size.9013d8ce.css rel=prefetch><link href=css/fixed-size.840ec49f.css rel=prefetch><link href=css/horizontal.c4223f3f.css rel=prefetch><link href=css/infinite-loading.4b238c18.css rel=prefetch><link href=css/keep-state.23037f2b.css rel=prefetch><link href=js/dynamic-size.631040e4.js rel=prefetch><link href=js/dynamic-size~fixed-size~horizontal~infinite-loading~keep-state.3b940789.js rel=prefetch><link href=js/fixed-size.9af085f6.js rel=prefetch><link href=js/horizontal.78fb7150.js rel=prefetch><link href=js/infinite-loading.8ae9073e.js rel=prefetch><link href=js/keep-state.0b3dbbf4.js rel=prefetch><link href=css/app.d2a3c8f3.css rel=preload as=style><link href=js/app.ba4d3385.js rel=preload as=script><link href=js/chunk-vendors.a8fb041f.js rel=preload as=script><link href=css/app.d2a3c8f3.css rel=stylesheet></head><body><div id=app></div><script src=js/chunk-vendors.a8fb041f.js></script><script src=js/app.ba4d3385.js></script></body></html>
1+
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><title>vue-virtual-scroll-list</title><link rel=icon href=favicon.png><link rel=stylesheet href=milligram.css><link rel=stylesheet href=highlight/theme.css><script src=highlight/pack.js></script><script>hljs.initHighlightingOnLoad()</script><link href=css/dynamic-size.9013d8ce.css rel=prefetch><link href=css/fixed-size.840ec49f.css rel=prefetch><link href=css/horizontal.c4223f3f.css rel=prefetch><link href=css/infinite-loading.4b238c18.css rel=prefetch><link href=css/keep-state.23037f2b.css rel=prefetch><link href=js/dynamic-size.631040e4.js rel=prefetch><link href=js/dynamic-size~fixed-size~horizontal~infinite-loading~keep-state.3b940789.js rel=prefetch><link href=js/fixed-size.9af085f6.js rel=prefetch><link href=js/horizontal.78fb7150.js rel=prefetch><link href=js/infinite-loading.8ae9073e.js rel=prefetch><link href=js/keep-state.0b3dbbf4.js rel=prefetch><link href=css/app.d2a3c8f3.css rel=preload as=style><link href=js/app.2bb6074c.js rel=preload as=script><link href=js/chunk-vendors.a8fb041f.js rel=preload as=script><link href=css/app.d2a3c8f3.css rel=stylesheet></head><body><div id=app></div><script src=js/chunk-vendors.a8fb041f.js></script><script src=js/app.2bb6074c.js></script></body></html>

docs/js/app.2bb6074c.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/js/app.2bb6074c.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/js/app.ba4d3385.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/js/app.ba4d3385.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

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)