Skip to content

Commit 4deb119

Browse files
committed
Add no more data and no results tips feature
1 parent e24f2da commit 4deb119

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/components/InfiniteLoading.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<div class="infinite-loading-container">
33
<i class="icon-loading" v-show="isLoading"></i>
4+
<div class="infinite-status-tips" v-show="!isLoading && isNoResults">
5+
<slot name="no-results">No results :(</slot>
6+
</div>
7+
<div class="infinite-status-tips" v-show="!isLoading && isNoMore">
8+
<slot name="no-more">No more data :)</slot>
9+
</div>
410
</div>
511
</template>
612
<script>
@@ -41,6 +47,8 @@
4147
isLoading: false,
4248
scrollParent: null,
4349
scrollHandler: null,
50+
isNoResults: false,
51+
isNoMore: false,
4452
};
4553
},
4654
props: {
@@ -72,9 +80,23 @@
7280
'$InfiniteLoading:loaded'() {
7381
this.isLoading = false;
7482
},
83+
'$InfiniteLoading:noResults'() {
84+
this.isLoading = false;
85+
this.isNoMore = false;
86+
this.isNoResults = true;
87+
this.scrollParent.removeEventListener('scroll', this.scrollHandler);
88+
},
89+
'$InfiniteLoading:noMore'() {
90+
this.isLoading = false;
91+
this.isNoResults = false;
92+
this.isNoMore = true;
93+
this.scrollParent.removeEventListener('scroll', this.scrollHandler);
94+
},
7595
},
7696
destroyed() {
77-
this.scrollParent.removeEventListener('scroll', this.scrollHandler);
97+
if (!this.isNoResults && !this.isNoMore) {
98+
this.scrollParent.removeEventListener('scroll', this.scrollHandler);
99+
}
78100
},
79101
};
80102
</script>
@@ -113,6 +135,13 @@
113135
}
114136
}
115137
138+
.infinite-status-tips{
139+
color: #666;
140+
font-size: 14px;
141+
text-align: center;
142+
padding: 10px 0;
143+
}
144+
116145
@keyframes loading{
117146
0%{
118147
transform: rotate(-38deg);

0 commit comments

Comments
 (0)