vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能示例
更新時(shí)間:2019年05月25日 10:56:08 作者:xudejun
這篇文章主要介紹了vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能,涉及基于vue的事件響應(yīng)、數(shù)據(jù)交互等相關(guān)操作技巧,需要的朋友可以參考下
本文實(shí)例講述了vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能。分享給大家供大家參考,具體如下:
加載狀態(tài)
<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="沒有更多數(shù)據(jù)了" :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
}
})
}
}
}
}
希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。
相關(guān)文章
vue3實(shí)現(xiàn)模擬地圖站點(diǎn)名稱按需顯示的功能(車輛模擬地圖)
最近在做車輛模擬地圖,在實(shí)現(xiàn)控制站點(diǎn)名稱按需顯示,下面通過本文給大家分享vue3實(shí)現(xiàn)模擬地圖站點(diǎn)名稱按需顯示的功能,感興趣的朋友跟隨小編一起看看吧2024-06-06
vue開發(fā)移動(dòng)端h5環(huán)境搭建的全過程
在正式使用Vue進(jìn)行移動(dòng)端頁(yè)面開發(fā)前,需要做一些前置工作,下面這篇文章主要給大家介紹了關(guān)于vue開發(fā)移動(dòng)端h5環(huán)境搭建的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
Vue3使用hooks解決字典數(shù)據(jù)的顯示問題
我們?cè)谑褂?nbsp;element-plus的時(shí)候,經(jīng)常會(huì)使用一些字典數(shù)據(jù), 在搜索框的時(shí)候,字典數(shù)數(shù)要使用 el-select el-option 來顯示,但是經(jīng)常會(huì)遇到字典數(shù)據(jù)的顯示問題,所以本文給大家介紹了Vue3使用hooks解決字典數(shù)據(jù)的顯示問題,需要的朋友可以參考下2024-12-12
在vue項(xiàng)目中集成graphql(vue-ApolloClient)
這篇文章主要介紹了在vue項(xiàng)目中集成graphql(vue-ApolloClient),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09

