|
1 | 1 | /*! |
2 | | - * vue-virtual-scroll-list v2.0.8 |
| 2 | + * vue-virtual-scroll-list v2.0.9 |
3 | 3 | * open source under the MIT license |
4 | 4 | * https://github.com/tangbc/vue-virtual-scroll-list#readme |
5 | 5 | */ |
|
113 | 113 | }, { |
114 | 114 | key: "getOffset", |
115 | 115 | value: function getOffset(start) { |
116 | | - return this.getIndexOffset(start); |
| 116 | + return start < 1 ? 0 : this.getIndexOffset(start); |
117 | 117 | } |
118 | 118 | }, { |
119 | 119 | key: "updateParam", |
|
581 | 581 | this.virtual.updateParam('uniqueIds', this.getUniqueIdFromDataSources()); |
582 | 582 | this.virtual.handleDataSourcesChange(); |
583 | 583 | } |
| 584 | + }, |
| 585 | + start: function start(newValue) { |
| 586 | + this.scrollToIndex(newValue); |
| 587 | + }, |
| 588 | + offset: function offset(newValue) { |
| 589 | + this.scrollToOffset(newValue); |
584 | 590 | } |
585 | 591 | }, |
586 | 592 | created: function created() { |
|
620 | 626 | }, |
621 | 627 | // set current scroll position to a expectant index |
622 | 628 | 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) { |
628 | 631 | this.scrollToBottom(); |
629 | 632 | } else { |
630 | 633 | var offset = this.virtual.getOffset(index); |
|
748 | 751 | var dataSource = this.dataSources[index]; |
749 | 752 |
|
750 | 753 | 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 | + } |
763 | 770 | } 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.")); |
765 | 772 | } |
766 | 773 | } |
767 | 774 |
|
|
0 commit comments