1
1
<template >
2
2
<div class =" infinite-loading-container" >
3
- <div v-show =" isLoading " >
3
+ <div v-show =" isShowSpinner " >
4
4
<slot name =" spinner" >
5
5
<spinner :spinner =" spinner" />
6
6
</slot >
7
7
</div >
8
- <div class =" infinite-status-prompt" v-show =" isNoResults " >
8
+ <div class =" infinite-status-prompt" v-show =" isShowNoResults " >
9
9
<slot name =" no-results" >{{ slots.noResults }}</slot >
10
10
</div >
11
- <div class =" infinite-status-prompt" v-show =" isNoMore " >
11
+ <div class =" infinite-status-prompt" v-show =" isShowNoMore " >
12
12
<slot name =" no-more" >{{ slots.noMore }}</slot >
13
13
</div >
14
14
</div >
15
15
</template >
16
16
<script >
17
17
/* eslint-disable no-console */
18
18
import Spinner from ' ./Spinner.vue' ;
19
- import config , { evt3rdArg , WARNINGS } from ' ../config' ;
19
+ import config , { evt3rdArg , WARNINGS , STATUS } from ' ../config' ;
20
20
import { throttleer , loopTracker , isBlankSlotElm } from ' ../utils' ;
21
21
22
22
export default {
@@ -25,33 +25,33 @@ export default {
25
25
return {
26
26
scrollParent: null ,
27
27
scrollHandler: null ,
28
- isLoading: false ,
29
- isComplete: false ,
30
28
isFirstLoad: true , // save the current loading whether it is the first loading
29
+ status: STATUS .READY ,
31
30
slots: config .slots ,
32
31
};
33
32
},
34
33
components: {
35
34
Spinner,
36
35
},
37
36
computed: {
38
- isNoResults: {
37
+ isShowSpinner () {
38
+ return this .status === STATUS .LOADING ;
39
+ },
40
+ isShowNoResults: {
39
41
cache: false , // disable cache to fix the problem of get slot text delay
40
42
get () {
41
43
return (
42
- ! this .isLoading
43
- && this .isComplete
44
+ this .status === STATUS .COMPLETE
44
45
&& this .isFirstLoad
45
46
&& ! isBlankSlotElm (this .$slots [' no-results' ])
46
47
);
47
48
},
48
49
},
49
- isNoMore : {
50
+ isShowNoMore : {
50
51
cache: false , // disable cache to fix the problem of get slot text delay
51
52
get () {
52
53
return (
53
- ! this .isLoading
54
- && this .isComplete
54
+ this .status === STATUS .COMPLETE
55
55
&& ! this .isFirstLoad
56
56
&& ! isBlankSlotElm (this .$slots [' no-more' ])
57
57
);
@@ -91,7 +91,7 @@ export default {
91
91
}, { immediate: true });
92
92
93
93
this .scrollHandler = function scrollHandlerOriginal (ev ) {
94
- if (! this .isLoading ) {
94
+ if (this .status === STATUS . READY ) {
95
95
if (ev && ev .constructor === Event ) {
96
96
throttleer .throttle (this .attemptLoad );
97
97
} else {
@@ -106,7 +106,7 @@ export default {
106
106
this .$on (' $InfiniteLoading:loaded' , (ev ) => {
107
107
this .isFirstLoad = false ;
108
108
109
- if (this .isLoading ) {
109
+ if (this .status === STATUS . LOADING ) {
110
110
this .$nextTick (this .attemptLoad .bind (null , true ));
111
111
}
112
112
@@ -116,8 +116,7 @@ export default {
116
116
});
117
117
118
118
this .$on (' $InfiniteLoading:complete' , (ev ) => {
119
- this .isLoading = false ;
120
- this .isComplete = true ;
119
+ this .status = STATUS .COMPLETE ;
121
120
122
121
// force re-complation computed properties to fix the problem of get slot text delay
123
122
this .$nextTick (() => {
@@ -132,8 +131,7 @@ export default {
132
131
});
133
132
134
133
this .$on (' $InfiniteLoading:reset' , (ev ) => {
135
- this .isLoading = false ;
136
- this .isComplete = false ;
134
+ this .status = STATUS .READY ;
137
135
this .isFirstLoad = true ;
138
136
throttleer .reset ();
139
137
this .scrollParent .addEventListener (' scroll' , this .scrollHandler , evt3rdArg);
@@ -167,7 +165,10 @@ export default {
167
165
* To adapt to keep-alive feature, but only work on Vue 2.2.0 and above, see: https://vuejs.org/v2/api/#keep-alive
168
166
*/
169
167
deactivated () {
170
- this .isLoading = false ;
168
+ /* istanbul ignore else */
169
+ if (this .status === STATUS .LOADING ) {
170
+ this .status = STATUS .READY ;
171
+ }
171
172
this .scrollParent .removeEventListener (' scroll' , this .scrollHandler , evt3rdArg);
172
173
},
173
174
activated () {
@@ -184,11 +185,11 @@ export default {
184
185
const currentDistance = this .getCurrentDistance ();
185
186
186
187
if (
187
- ! this .isComplete
188
+ this .status !== STATUS . COMPLETE
188
189
&& currentDistance <= this .distance
189
190
&& (this .$el .offsetWidth + this .$el .offsetHeight ) > 0
190
191
) {
191
- this .isLoading = true ;
192
+ this .status = STATUS . LOADING ;
192
193
193
194
if (typeof this .onInfinite === ' function' ) {
194
195
this .onInfinite .call (null , this .stateChanger );
@@ -202,7 +203,7 @@ export default {
202
203
loopTracker .track ();
203
204
}
204
205
} else {
205
- this .isLoading = false ;
206
+ this .status = STATUS . READY ;
206
207
}
207
208
},
208
209
/**
@@ -253,7 +254,8 @@ export default {
253
254
},
254
255
},
255
256
destroyed () {
256
- if (! this .isComplete ) {
257
+ /* istanbul ignore else */
258
+ if (! this .status !== STATUS .COMPLETE ) {
257
259
this .scrollParent .removeEventListener (' scroll' , this .scrollHandler , evt3rdArg);
258
260
}
259
261
},
0 commit comments