Skip to content

Commit f9a665c

Browse files
committed
feat: add error status and support retry in error slot (#159) (#181)
1 parent aa86488 commit f9a665c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/components/InfiniteLoading.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
<div class="infinite-status-prompt" v-show="isShowNoMore">
1212
<slot name="no-more">{{ slots.noMore }}</slot>
1313
</div>
14+
<div class="infinite-status-prompt" v-show="isShowError">
15+
<slot name="error" :trigger="attemptLoad">
16+
{{ slots.error }}
17+
<br>
18+
<button
19+
class="btn-try-infinite"
20+
@click="attemptLoad"
21+
v-text="slots.errorBtnText">
22+
</button>
23+
</slot>
24+
</div>
1425
</div>
1526
</template>
1627
<script>
@@ -37,6 +48,9 @@ export default {
3748
isShowSpinner() {
3849
return this.status === STATUS.LOADING;
3950
},
51+
isShowError() {
52+
return this.status === STATUS.ERROR;
53+
},
4054
isShowNoResults: {
4155
cache: false, // disable cache to fix the problem of get slot text delay
4256
get() {
@@ -159,6 +173,10 @@ export default {
159173
reset: () => {
160174
this.$emit('$InfiniteLoading:reset', { target: this });
161175
},
176+
error: () => {
177+
this.status = STATUS.ERROR;
178+
throttleer.reset();
179+
},
162180
};
163181
},
164182
/**
@@ -284,5 +302,22 @@ export default {
284302
font-size: 14px;
285303
text-align: center;
286304
padding: 10px 0;
305+
306+
.btn-try-infinite {
307+
margin-top: 5px;
308+
padding: 5px 10px;
309+
color: #999;
310+
font-size: 14px;
311+
line-height: 1;
312+
background: transparent;
313+
border: 1px solid #ccc;
314+
border-radius: 3px;
315+
outline: none;
316+
cursor: pointer;
317+
318+
&:not(:active):hover {
319+
opacity: 0.8;
320+
}
321+
}
287322
}
288323
</style>

src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const system = {
3434
const slots = {
3535
noResults: 'No results :(',
3636
noMore: 'No more data :)',
37+
error: 'Opps, something went wrong :(',
38+
errorBtnText: 'Retry',
3739
};
3840

3941
/**
@@ -121,6 +123,7 @@ export const STATUS = {
121123
READY: 0,
122124
LOADING: 1,
123125
COMPLETE: 2,
126+
ERROR: 3,
124127
};
125128

126129
export default {

0 commit comments

Comments
 (0)