vue-infinite-loading
安装
npm install vue-infinite-loading --save
基本使用
<template>
<div>
<div class="article-main" v-for="(item,index) in blogList" :key="index">
{{item.title}}
{{item.description}}
</div>
<infinite-loading
spinner="spiral"
@infinite="infiniteHandler"
:distance="200"
class="infinite-loading-wrap"
>
<div slot="spinner">Loading...</div>
<div slot="no-more">No more Data</div>
<div slot="no-results">No results Data</div>
<div slot="error" slot-scope="{ trigger }">
Error Data, click <a href="javascript:;" @click="trigger">here</a> toretry
</div>
</infinite-loading>
</div>
</template>
<script>
import InfiniteLoading from 'vue-infinite-loading'
export default {
name: "",
data(){
return{
blogList:[],
}
},
components: {
InfiniteLoading
},
methods:{
infiniteHandler($state) {
this.$axios
.get("请求地址")
.then((res) => {
if(res.data.data.length) {
let arr = res.data.data;
this.blogList = [...this.blogList,...arr]
console.log(this.blogList)
$state.loaded();
}else {
$state.complete();
}
})
},
}
}
</script>
tips: 如果发现每次加载的数据都是相同的,可以问问后端。我就是加载的数据一直是相同的,然后自己弄了很久,后面发现是后端要设置一些东西,裂开。
|