2020-08-13 15:18:26 +08:00
## InfiniteScroll
Load more data while reach bottom of the page
### Basic usage
Add `v-infinite-scroll` to the list to automatically execute loading method when scrolling to the bottom.
:::demo
```html
< template >
< ul class = "infinite-list" v-infinite-scroll = "load" style = "overflow:auto" >
< li v-for = "i in count" class = "infinite-list-item" > {{ i }}< / li >
< / ul >
< / template >
< script >
export default {
data () {
return {
count: 0
}
},
methods: {
load () {
this.count += 2
}
}
}
< / script >
2021-06-10 00:23:50 +08:00
<!--
< setup >
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const count = ref(0);
const load = () => {
count.value += 2;
};
return {
count,
load,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
### Disable Loading
:::demo
```html
< template >
< div class = "infinite-list-wrapper" style = "overflow:auto" >
< ul
class="list"
v-infinite-scroll="load"
infinite-scroll-disabled="disabled">
< li v-for = "i in count" class = "list-item" > {{ i }}< / li >
< / ul >
< p v-if = "loading" > Loading...< / p >
< p v-if = "noMore" > No more< / p >
< / div >
< / template >
< script >
export default {
data () {
return {
count: 10,
loading: false
}
},
computed: {
noMore () {
return this.count >= 20
},
disabled () {
return this.loading || this.noMore
}
},
methods: {
load () {
this.loading = true
setTimeout(() => {
this.count += 2
this.loading = false
}, 2000)
}
}
}
< / script >
2021-06-10 00:23:50 +08:00
<!--
< setup >
import { defineComponent, ref, computed } from 'vue';
export default defineComponent({
setup() {
const count = ref(10);
const loading = ref(false);
const noMore = computed(() => count.value >= 20);
const disabled = computed(() => loading.value || noMore.value);
const load = () => {
loading.value = true;
setTimeout(() => {
count.value += 2;
loading.value = false;
}, 2000);
};
return {
count,
loading,
noMore,
disabled,
load,
};
},
});
< / setup >
-->
2020-08-13 15:18:26 +08:00
```
:::
2021-04-06 11:41:02 +08:00
### Directives
2020-08-13 15:18:26 +08:00
2021-04-06 11:41:02 +08:00
| Name | Description | Type | Accepted values | Default |
2020-08-13 15:18:26 +08:00
| -------------- | ------------------------------ | --------- | ------------------------------------ | ------- |
2021-04-06 11:41:02 +08:00
| v-infinite-scroll | Load more data while reach bottom of the page | function | - | - |
2020-08-13 15:18:26 +08:00
| infinite-scroll-disabled | is disabled | boolean | - |false |
| infinite-scroll-delay | throttle delay (ms) | number | - |200 |
| infinite-scroll-distance| trigger distance (px) | number |- |0 |
| infinite-scroll-immediate |Whether to execute the loading method immediately, in case the content cannot be filled up in the initial state. | boolean | - |true |