2020-11-04 10:30:14 +08:00
|
|
|
## InfiniteScroll
|
|
|
|
|
|
|
|
ページ下部に到達している間にさらに多くのデータを読み込む
|
|
|
|
|
|
|
|
### 基本的な使い方
|
2021-09-04 19:29:28 +08:00
|
|
|
|
2020-11-04 10:30:14 +08:00
|
|
|
リストに `v-infinite-scroll` を追加し、下までスクロールしたときに自動的にロードメソッドを実行するようにする。
|
|
|
|
:::demo
|
2021-09-04 19:29:28 +08:00
|
|
|
|
2020-11-04 10:30:14 +08:00
|
|
|
```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 {
|
2021-09-04 19:29:28 +08:00
|
|
|
data() {
|
2020-11-04 10:30:14 +08:00
|
|
|
return {
|
2021-09-04 19:29:28 +08:00
|
|
|
count: 0,
|
2020-11-04 10:30:14 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-09-04 19:29:28 +08:00
|
|
|
load() {
|
2020-11-04 10:30:14 +08:00
|
|
|
this.count += 2
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
|
|
|
},
|
2020-11-04 10:30:14 +08:00
|
|
|
}
|
|
|
|
</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-11-04 10:30:14 +08:00
|
|
|
```
|
2021-09-04 19:29:28 +08:00
|
|
|
|
2020-11-04 10:30:14 +08:00
|
|
|
:::
|
|
|
|
|
|
|
|
### ローディングを無効化
|
|
|
|
|
|
|
|
:::demo
|
2021-09-04 19:29:28 +08:00
|
|
|
|
2020-11-04 10:30:14 +08:00
|
|
|
```html
|
|
|
|
<template>
|
|
|
|
<div class="infinite-list-wrapper" style="overflow:auto">
|
2020-11-09 13:55:57 +08:00
|
|
|
<ul>
|
2021-09-04 19:29:28 +08:00
|
|
|
class="list" v-infinite-scroll="load" infinite-scroll-disabled="disabled">
|
2020-11-04 10:30:14 +08:00
|
|
|
<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 {
|
2021-09-04 19:29:28 +08:00
|
|
|
data() {
|
2020-11-04 10:30:14 +08:00
|
|
|
return {
|
|
|
|
count: 10,
|
2021-09-04 19:29:28 +08:00
|
|
|
loading: false,
|
2020-11-04 10:30:14 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2021-09-04 19:29:28 +08:00
|
|
|
noMore() {
|
2020-11-04 10:30:14 +08:00
|
|
|
return this.count >= 20
|
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
disabled() {
|
2020-11-04 10:30:14 +08:00
|
|
|
return this.loading || this.noMore
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
2020-11-04 10:30:14 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2021-09-04 19:29:28 +08:00
|
|
|
load() {
|
2020-11-04 10:30:14 +08:00
|
|
|
this.loading = true
|
|
|
|
setTimeout(() => {
|
|
|
|
this.count += 2
|
|
|
|
this.loading = false
|
|
|
|
}, 2000)
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
|
|
|
},
|
2020-11-04 10:30:14 +08:00
|
|
|
}
|
|
|
|
</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-11-04 10:30:14 +08:00
|
|
|
```
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
:::
|
2020-11-04 10:30:14 +08:00
|
|
|
|
|
|
|
### 属性
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
| Attribute | Description | Type | Accepted values | Default |
|
|
|
|
| ------------------------- | ---------------------------------------------------------------------------------- | ------- | --------------- | ------- |
|
|
|
|
| infinite-scroll-disabled | 無効かどうか | boolean | - | false |
|
|
|
|
| infinite-scroll-delay | スロットルディレイ(ms) | number | - | 200 |
|
|
|
|
| infinite-scroll-distance | トリガー距離(px) | number | - | 0 |
|
|
|
|
| infinite-scroll-immediate | 初期状態でコンテンツが埋まらない場合に、すぐに読み込みメソッドを実行するかどうか。 | boolean | - | true |
|