1
1
<template >
2
2
<div class =" infinite-loading-container" >
3
- <div v-show =" isShowSpinner" >
3
+ <div
4
+ class =" infinite-status-prompt"
5
+ v-show =" isShowSpinner"
6
+ :style =" slotStyles.spinner" >
4
7
<slot name =" spinner" >
5
8
<spinner :spinner =" spinner" />
6
9
</slot >
7
10
</div >
8
- <div class =" infinite-status-prompt" v-show =" isShowNoResults" >
11
+ <div
12
+ class =" infinite-status-prompt"
13
+ :style =" slotStyles.noResults"
14
+ v-show =" isShowNoResults" >
9
15
<slot name =" no-results" >
10
16
<component v-if =" slots.noResults.render" :is =" slots.noResults" ></component >
11
17
<template v-else >{{ slots.noResults }}</template >
12
18
</slot >
13
19
</div >
14
- <div class =" infinite-status-prompt" v-show =" isShowNoMore" >
20
+ <div
21
+ class =" infinite-status-prompt"
22
+ :style =" slotStyles.noMore"
23
+ v-show =" isShowNoMore" >
15
24
<slot name =" no-more" >
16
25
<component v-if =" slots.noMore.render" :is =" slots.noMore" ></component >
17
26
<template v-else >{{ slots.noMore }}</template >
18
27
</slot >
19
28
</div >
20
- <div class =" infinite-status-prompt" v-show =" isShowError" >
29
+ <div
30
+ class =" infinite-status-prompt"
31
+ :style =" slotStyles.error"
32
+ v-show =" isShowError" >
21
33
<slot name =" error" :trigger =" attemptLoad" >
22
34
<component
23
35
v-if =" slots.error.render"
39
51
</template >
40
52
<script >
41
53
import Spinner from ' ./Spinner.vue' ;
42
- import config , { evt3rdArg , WARNINGS , STATUS } from ' ../config' ;
54
+ import config, {
55
+ evt3rdArg , WARNINGS , STATUS , SLOT_STYLES ,
56
+ } from ' ../config' ;
43
57
import {
44
- warn , throttleer , loopTracker , isBlankSlotElm , scrollBarStorage ,
58
+ warn , throttleer , loopTracker , scrollBarStorage , kebabCase ,
45
59
} from ' ../utils' ;
46
60
47
61
export default {
@@ -65,25 +79,42 @@ export default {
65
79
isShowError () {
66
80
return this .status === STATUS .ERROR ;
67
81
},
68
- isShowNoResults: {
69
- cache: false , // disable cache to fix the problem of get slot text delay
70
- get () {
71
- return (
72
- this .status === STATUS .COMPLETE
73
- && this .isFirstLoad
74
- && ! isBlankSlotElm (this .$slots [' no-results' ])
75
- );
76
- },
82
+ isShowNoResults () {
83
+ return (
84
+ this .status === STATUS .COMPLETE
85
+ && this .isFirstLoad
86
+ );
77
87
},
78
- isShowNoMore: {
79
- cache: false , // disable cache to fix the problem of get slot text delay
80
- get () {
81
- return (
82
- this .status === STATUS .COMPLETE
83
- && ! this .isFirstLoad
84
- && ! isBlankSlotElm (this .$slots [' no-more' ])
85
- );
86
- },
88
+ isShowNoMore () {
89
+ return (
90
+ this .status === STATUS .COMPLETE
91
+ && ! this .isFirstLoad
92
+ );
93
+ },
94
+ slotStyles () {
95
+ const styles = {};
96
+
97
+ Object .keys (config .slots ).forEach ((key ) => {
98
+ const name = kebabCase (key);
99
+
100
+ if (
101
+ // no slot and the configured default slot is not a Vue component
102
+ (
103
+ ! this .$slots [name]
104
+ && ! config .slots [key].render
105
+ )
106
+ // has slot and slot is pure text node
107
+ || (
108
+ this .$slots [name]
109
+ && ! this .$slots [name][0 ].tag
110
+ )
111
+ ) {
112
+ // only apply default styles for pure text slot
113
+ styles[key] = SLOT_STYLES ;
114
+ }
115
+ });
116
+
117
+ return styles;
87
118
},
88
119
},
89
120
props: {
@@ -177,10 +208,6 @@ export default {
177
208
}
178
209
});
179
210
180
- if (this .onInfinite ) {
181
- warn (WARNINGS .INFINITE_EVENT );
182
- }
183
-
184
211
/**
185
212
* change state for this component, pass to the callback
186
213
*/
@@ -199,6 +226,10 @@ export default {
199
226
throttleer .reset ();
200
227
},
201
228
};
229
+
230
+ if (this .onInfinite ) {
231
+ warn (WARNINGS .INFINITE_EVENT );
232
+ }
202
233
},
203
234
/**
204
235
* To adapt to keep-alive feature, but only work on Vue 2.2.0 and above, see: https://vuejs.org/v2/api/#keep-alive
@@ -315,10 +346,11 @@ export default {
315
346
.infinite-loading-container {
316
347
clear : both ;
317
348
text-align : center ;
349
+
318
350
@{deep} * [class^= loading- ] {
319
351
@size : 28px ;
320
352
display : inline-block ;
321
- margin : 15 px 0 ;
353
+ margin : 5 px 0 ;
322
354
width : @size ;
323
355
height : @size ;
324
356
font-size : @size ;
@@ -327,27 +359,20 @@ export default {
327
359
}
328
360
}
329
361
330
- .infinite-status-prompt {
331
- color : #666 ;
362
+ .btn-try-infinite {
363
+ margin-top : 5px ;
364
+ padding : 5px 10px ;
365
+ color : #999 ;
332
366
font-size : 14px ;
333
- text-align : center ;
334
- padding : 10px 0 ;
335
-
336
- .btn-try-infinite {
337
- margin-top : 5px ;
338
- padding : 5px 10px ;
339
- color : #999 ;
340
- font-size : 14px ;
341
- line-height : 1 ;
342
- background : transparent ;
343
- border : 1px solid #ccc ;
344
- border-radius : 3px ;
345
- outline : none ;
346
- cursor : pointer ;
347
-
348
- & :not (:active ):hover {
349
- opacity : 0.8 ;
350
- }
367
+ line-height : 1 ;
368
+ background : transparent ;
369
+ border : 1px solid #ccc ;
370
+ border-radius : 3px ;
371
+ outline : none ;
372
+ cursor : pointer ;
373
+
374
+ & :not (:active ):hover {
375
+ opacity : 0.8 ;
351
376
}
352
377
}
353
378
</style >
0 commit comments