|
1 | 1 | <template>
|
2 | 2 | <div class="infinite-loading-container">
|
3 | 3 | <i :class="spinnerType" v-show="isLoading"></i>
|
4 |
| - <div class="infinite-status-prompt" v-show="!isLoading && isNoResults"> |
| 4 | + <div class="infinite-status-prompt" v-show="!isLoading && isComplete && isFirstLoad"> |
5 | 5 | <slot name="no-results">No results :(</slot>
|
6 | 6 | </div>
|
7 |
| - <div class="infinite-status-prompt" v-show="!isLoading && isNoMore"> |
| 7 | + <div class="infinite-status-prompt" v-show="!isLoading && isComplete && !isFirstLoad"> |
8 | 8 | <slot name="no-more">No more data :)</slot>
|
9 | 9 | </div>
|
10 | 10 | </div>
|
|
52 | 52 | export default {
|
53 | 53 | data() {
|
54 | 54 | return {
|
55 |
| - isLoading: false, |
56 | 55 | scrollParent: null,
|
57 | 56 | scrollHandler: null,
|
58 |
| - isNoResults: false, |
59 |
| - isNoMore: false, |
| 57 | + isLoading: false, |
| 58 | + isComplete: false, |
| 59 | + isFirstLoad: true, // save the current loading whether it is the first loading |
60 | 60 | };
|
61 | 61 | },
|
62 | 62 | computed: {
|
|
90 | 90 | this.scrollParent.addEventListener('scroll', this.scrollHandler);
|
91 | 91 | },
|
92 | 92 | events: {
|
93 |
| - // Hide the loading icon when data was loaded |
94 | 93 | '$InfiniteLoading:loaded': function loaded() {
|
95 | 94 | this.isLoading = false;
|
| 95 | + this.isFirstLoad = false; |
96 | 96 | },
|
97 |
| - '$InfiniteLoading:noResults': function noResults() { |
98 |
| - this.isLoading = false; |
99 |
| - this.isNoMore = false; |
100 |
| - this.isNoResults = true; |
101 |
| - this.scrollParent.removeEventListener('scroll', this.scrollHandler); |
102 |
| - }, |
103 |
| - '$InfiniteLoading:noMore': function noMore() { |
| 97 | + '$InfiniteLoading:complete': function complete() { |
104 | 98 | this.isLoading = false;
|
105 |
| - this.isNoResults = false; |
106 |
| - this.isNoMore = true; |
| 99 | + this.isComplete = true; |
107 | 100 | this.scrollParent.removeEventListener('scroll', this.scrollHandler);
|
108 | 101 | },
|
109 | 102 | '$InfiniteLoading:reset': function reset() {
|
110 | 103 | this.isLoading = false;
|
111 |
| - this.isNoMore = false; |
112 |
| - this.isNoResults = false; |
| 104 | + this.isComplete = false; |
| 105 | + this.isFirstLoad = true; |
113 | 106 | this.scrollParent.addEventListener('scroll', this.scrollHandler);
|
114 | 107 | setTimeout(this.scrollHandler, 1);
|
115 | 108 | },
|
116 | 109 | },
|
117 | 110 | destroyed() {
|
118 |
| - if (!this.isNoResults && !this.isNoMore) { |
| 111 | + if (!this.isComplete) { |
119 | 112 | this.scrollParent.removeEventListener('scroll', this.scrollHandler);
|
120 | 113 | }
|
121 | 114 | },
|
|
0 commit comments