vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁功能示例
更新時(shí)間:2019年05月25日 10:56:08 作者:xudejun
這篇文章主要介紹了vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁功能,涉及基于vue的事件響應(yīng)、數(shù)據(jù)交互等相關(guān)操作技巧,需要的朋友可以參考下
本文實(shí)例講述了vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁功能。分享給大家供大家參考,具體如下:
加載狀態(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 } }) } } } }
希望本文所述對大家vue.js程序設(shè)計(jì)有所幫助。
相關(guān)文章
vue 組件數(shù)據(jù)加載解析順序的詳細(xì)代碼
Vue.js的解析順序可以概括為:模板編譯、組件創(chuàng)建、數(shù)據(jù)渲染、事件處理和生命周期鉤子函數(shù)執(zhí)行,接下來通過本文給大家介紹vue 組件數(shù)據(jù)加載解析順序的完整代碼,感興趣的朋友跟隨小編一起看看吧2024-03-03vue基礎(chǔ)之使用get、post、jsonp實(shí)現(xiàn)交互功能示例
這篇文章主要介紹了vue基礎(chǔ)之使用get、post、jsonp實(shí)現(xiàn)交互功能,結(jié)合實(shí)例形式分析了vue.js中g(shù)et、post及jsonp針對本地文件、網(wǎng)絡(luò)接口實(shí)現(xiàn)交互功能相關(guān)操作技巧,需要的朋友可以參考下2019-03-03VUE微信H5生成二維碼海報(bào)保存在本地相冊的實(shí)現(xiàn)
本文主要介紹了VUE微信H5生成二維碼海報(bào)保存在本地相冊的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06使用Webpack提高Vue.js應(yīng)用的方式匯總(四種)
Webpack是開發(fā)Vue.js單頁應(yīng)用程序的重要工具。下面通過四種方式給大家介紹使用Webpack提高Vue.js應(yīng)用,需要的的朋友參考下吧2017-07-07vue 數(shù)據(jù)(data)賦值問題的解決方案
這篇文章主要介紹了vue 數(shù)據(jù)(data)賦值問題的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03改變vue請求過來的數(shù)據(jù)中的某一項(xiàng)值的方法(詳解)
下面小編就為大家分享一篇改變vue請求過來的數(shù)據(jù)中的某一項(xiàng)值的方法(詳解),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03