滚动加载:滚动至底部时,加载更多数据。
1.如何使用?
//在要实现滚动加载的列表上上添加v-infinite-scroll,并赋值相应的加载方法,
//可实现滚动到底部时自动执行加载方法。
<template>
<ul class="infinite-list" v-infinite-scroll="loadMore" 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: {
loadMore () {
this.count += 2
}
}
}
</script>
2.禁用加载
<template>
<div class="infinite-list-wrapper" style="overflow:auto">
<ul
class="list"
v-infinite-scroll="loadMore"
infinite-scroll-disabled="disabled">
<li v-for="i in count" class="list-item">{{ i }}</li>
</ul>
<p v-if="loading">加载中...</p>
<p v-if="noMore">没有更多了</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: {
loadMore () {
this.loading = true
setTimeout(() => {
this.count += 2
this.loading = false
}, 2000)
}
}
}
</script>
关于滚动加载的大致内容就是这些,如果想要深入浅出请前往滚动加载