Plugins
页面无限加载
import infiniteScroll from 'vue-infinite-scroll'
Vue.use(infiniteScroll)<!-- 书单列表 -->
<style rel="stylesheet/scss" lang="scss">
</style>
<template>
<div class="row mt-3">
<div :class="CONTAINER_CLASSES" v-infinite-scroll="loadMore" infinite-scroll-disable="busy">
<book-item v-for="(item, index) in books" v-bind:key="index" :bookInfo="item"/>
</div>
</div>
</template>
<script>
import { getBooks } from '@/api/book'
import BookItem from './components/BookItem'
import {CONTAINER_CLASSES} from '@/styles/common'
export default {
name: 'bookList',
data: () => {
return {
CONTAINER_CLASSES: CONTAINER_CLASSES,
books: [],
busy: false,
page: 1
}
},
methods: {
loadMore: function () {
let that = this
that.busy = true
setTimeout(() => {
getBooks({page: that.page}).then((res) => {
if (res.status === 200 && res.statusText === 'OK') {
this.page += 1
let data = res.data.results
data.forEach((item) => {
that.books.push(item)
})
}
}).catch((error) => {
console.log(error)
})
})
}
},
components: {
BookItem
}
}
</script>Font Awesome
安装
旋转
参考
EditorMD
最后更新于