|
41 | 41 | import Spinner from './Spinner.vue';
|
42 | 42 | import config, { evt3rdArg, WARNINGS, STATUS } from '../config';
|
43 | 43 | import {
|
44 |
| - warn, throttleer, loopTracker, isBlankSlotElm, |
| 44 | + warn, throttleer, loopTracker, isBlankSlotElm, scrollBarStorage, |
45 | 45 | } from '../utils';
|
46 | 46 |
|
47 | 47 | export default {
|
@@ -133,6 +133,13 @@ export default {
|
133 | 133 | this.$on('$InfiniteLoading:loaded', (ev) => {
|
134 | 134 | this.isFirstLoad = false;
|
135 | 135 |
|
| 136 | + if (this.direction === 'top') { |
| 137 | + // wait for DOM updated |
| 138 | + this.$nextTick(() => { |
| 139 | + scrollBarStorage.restore(this.scrollParent); |
| 140 | + }); |
| 141 | + } |
| 142 | +
|
136 | 143 | if (this.status === STATUS.LOADING) {
|
137 | 144 | this.$nextTick(this.attemptLoad.bind(null, true));
|
138 | 145 | }
|
@@ -161,6 +168,7 @@ export default {
|
161 | 168 | this.status = STATUS.READY;
|
162 | 169 | this.isFirstLoad = true;
|
163 | 170 | throttleer.reset();
|
| 171 | + scrollBarStorage.remove(this.scrollParent); |
164 | 172 | this.scrollParent.addEventListener('scroll', this.scrollHandler, evt3rdArg);
|
165 | 173 | setTimeout(this.scrollHandler, 1);
|
166 | 174 |
|
@@ -222,6 +230,13 @@ export default {
|
222 | 230 | ) {
|
223 | 231 | this.status = STATUS.LOADING;
|
224 | 232 |
|
| 233 | + if (this.direction === 'top') { |
| 234 | + // wait for spinner display |
| 235 | + this.$nextTick(() => { |
| 236 | + scrollBarStorage.save(this.scrollParent); |
| 237 | + }); |
| 238 | + } |
| 239 | +
|
225 | 240 | if (typeof this.onInfinite === 'function') {
|
226 | 241 | this.onInfinite.call(null, this.stateChanger);
|
227 | 242 | } else {
|
@@ -287,6 +302,8 @@ export default {
|
287 | 302 | destroyed() {
|
288 | 303 | /* istanbul ignore else */
|
289 | 304 | if (!this.status !== STATUS.COMPLETE) {
|
| 305 | + throttleer.reset(); |
| 306 | + scrollBarStorage.remove(this.scrollParent); |
290 | 307 | this.scrollParent.removeEventListener('scroll', this.scrollHandler, evt3rdArg);
|
291 | 308 | }
|
292 | 309 | },
|
|
0 commit comments