Skip to content

Commit 4565c80

Browse files
committed
Add load result hide support through blank slots #61
1 parent 97edaa6 commit 4565c80

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/components/InfiniteLoading.vue

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<i :class="spinnerType"></i>
66
</slot>
77
</div>
8-
<div class="infinite-status-prompt" v-show="!isLoading && isComplete && isFirstLoad">
8+
<div class="infinite-status-prompt" v-show="isNoResults">
99
<slot name="no-results">No results :(</slot>
1010
</div>
11-
<div class="infinite-status-prompt" v-show="!isLoading && isComplete && !isFirstLoad">
11+
<div class="infinite-status-prompt" v-show="isNoMore">
1212
<slot name="no-more">No more data :)</slot>
1313
</div>
1414
</div>
@@ -78,6 +78,24 @@
7878
spinnerType() {
7979
return spinnerMapping[this.spinner] || spinnerMapping.default;
8080
},
81+
isNoResults: {
82+
cache: false, // disable cache to fix the problem of get slot text delay
83+
get() {
84+
const noResultsSlot = this.$slots['no-results'];
85+
const isBlankNoResultsSlot = (noResultsSlot && noResultsSlot[0].elm && noResultsSlot[0].elm.textContent === '');
86+
87+
return !this.isLoading && this.isComplete && this.isFirstLoad && !isBlankNoResultsSlot;
88+
},
89+
},
90+
isNoMore: {
91+
cache: false, // disable cache to fix the problem of get slot text delay
92+
get() {
93+
const noMoreSlot = this.$slots['no-more'];
94+
const isBlankNoMoreSlot = (noMoreSlot && noMoreSlot[0].elm && noMoreSlot[0].elm.textContent === '');
95+
96+
return !this.isLoading && this.isComplete && !this.isFirstLoad && !isBlankNoMoreSlot;
97+
},
98+
},
8199
},
82100
props: {
83101
distance: {
@@ -109,11 +127,18 @@
109127
this.$nextTick(this.attemptLoad);
110128
}
111129
});
130+
112131
this.$on('$InfiniteLoading:complete', () => {
113132
this.isLoading = false;
114133
this.isComplete = true;
134+
135+
// force re-complation computed properties to fix the problem of get slot text delay
136+
this.$nextTick(() => {
137+
this.$forceUpdate();
138+
});
115139
this.scrollParent.removeEventListener('scroll', this.scrollHandler);
116140
});
141+
117142
this.$on('$InfiniteLoading:reset', () => {
118143
this.isLoading = false;
119144
this.isComplete = false;

0 commit comments

Comments
 (0)