Skip to content

Commit 4ef21e4

Browse files
committed
refactor: optimize slot display logic
1 parent d3bb457 commit 4ef21e4

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/components/InfiniteLoading.vue

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
</slot>
77
</div>
88
<div class="infinite-status-prompt" v-show="isNoResults">
9-
<slot name="no-results" v-text="slots.noResults"></slot>
9+
<slot name="no-results">{{ slots.noResults }}</slot>
1010
</div>
1111
<div class="infinite-status-prompt" v-show="isNoMore">
12-
<slot name="no-more" v-text="slots.noMore"></slot>
12+
<slot name="no-more">{{ slots.noMore }}</slot>
1313
</div>
1414
</div>
1515
</template>
@@ -18,6 +18,20 @@
1818
import Spinner from './Spinner.vue';
1919
import config, { evt3rdArg, WARNINGS, ERRORS } from '../config';
2020
21+
/**
22+
* determine slot is or not a empty element
23+
* @param {Slot} slot target slot
24+
* @return {Boolean}
25+
*/
26+
function isBlankSlotElm(slot) {
27+
return (
28+
slot
29+
&& slot[0].elm
30+
&& slot[0].elm.textContent === ''
31+
&& slot[0].elm.childNodes.length === 0
32+
);
33+
}
34+
2135
export default {
2236
name: 'InfiniteLoading',
2337
data() {
@@ -42,19 +56,23 @@ export default {
4256
isNoResults: {
4357
cache: false, // disable cache to fix the problem of get slot text delay
4458
get() {
45-
const noResultsSlot = this.$slots['no-results'];
46-
const isBlankNoResultsSlot = (noResultsSlot && noResultsSlot[0].elm && noResultsSlot[0].elm.textContent === '');
47-
48-
return !this.isLoading && this.isComplete && this.isFirstLoad && !isBlankNoResultsSlot;
59+
return (
60+
!this.isLoading
61+
&& this.isComplete
62+
&& this.isFirstLoad
63+
&& !isBlankSlotElm(this.$slots['no-results'])
64+
);
4965
},
5066
},
5167
isNoMore: {
5268
cache: false, // disable cache to fix the problem of get slot text delay
5369
get() {
54-
const noMoreSlot = this.$slots['no-more'];
55-
const isBlankNoMoreSlot = (noMoreSlot && noMoreSlot[0].elm && noMoreSlot[0].elm.textContent === '');
56-
57-
return !this.isLoading && this.isComplete && !this.isFirstLoad && !isBlankNoMoreSlot;
70+
return (
71+
!this.isLoading
72+
&& this.isComplete
73+
&& !this.isFirstLoad
74+
&& !isBlankSlotElm(this.$slots['no-more'])
75+
);
5876
},
5977
},
6078
},

0 commit comments

Comments
 (0)