vue实现的上拉加载更多数据/分页功能示例
程序员文章站
2023-12-04 22:20:34
本文实例讲述了vue实现的上拉加载更多数据/分页功能。分享给大家供大家参考,具体如下:
加载状态
...
本文实例讲述了vue实现的上拉加载更多数据/分页功能。分享给大家供大家参考,具体如下:
加载状态
<div v-if='has_log == 0'> <load-more tip="上拉加载" :show-loading="false" background-color="#fbf9fe"></load-more> </div> <div v-if='has_log == 1'> <load-more tip="正在加载" :show-loading="true"></load-more> </div> <div v-if='has_log == 2'> <load-more tip="没有更多数据了" :show-loading="false" background-color="#fbf9fe"></load-more> </div>
js
export default { name: '', data () { return { list: [], now_item: '', current_index: 0, list_param: {page: 1}, no_data: false, has_log: 0 } }, components: { xinput }, created () { this.get('/api/index/index', this.list_param).then((data) => { this.list = data.data.data this.list_param.page += 1 }) window.addeventlistener('scroll', this.onscroll) }, methods: { onscroll () { this.has_log = 1 let innerheight = document.queryselector('#app').clientheight let outerheight = document.documentelement.clientheight let scrolltop = document.documentelement.scrolltop // console.log(innerheight + ' ' + outerheight + ' ' + scrolltop) // console.log(outerheight + scrolltop - 30) // console.log(innerheight) if (outerheight + scrolltop === innerheight + 57) { if (this.no_data === true) { this.has_log = 2 return false } this.get('/api/index/index', this.list_param).then((data) => { if (data.data.data.length > 0) { this.list = [...this.list, ...data.data.data] this.list_param.page = this.list_param.page + 1 this.has_log = 0 } else { this.has_log = 2 this.no_data = true } }) } } } }
希望本文所述对大家vue.js程序设计有所帮助。