vue實(shí)現(xiàn)純前端表格滾動(dòng)分頁加載
本文實(shí)例為大家分享了vue實(shí)現(xiàn)表格滾動(dòng)分頁加載的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)效果

實(shí)現(xiàn)過程
<div
? ? style="width: 100%; overflow: hidden; position: relative"
? ? id="container"
? ? ref="container"
? ? @mousewheel="handleScroll"
? ? :style="{ height: pageHeight + 'px' }">
? <!-- ? ?表格-->
? <div class="loading-bottom" v-show="visibleLoading">
? ? ? <a-spin :spinning="visibleLoading" style="margin-right: 10px"></a-spin>正在加載數(shù)據(jù)
? ? </div>
</div>js
data() {
? return {
? ? visibleLoading: false,
? }
},
mounted() {
? //ref指向?qū)?yīng)div,不建議對(duì)window全局監(jiān)聽,會(huì)影響子div的滾動(dòng)
? this.$refs.container.addEventListener('scroll', this.handleScroll);
},
beforeUnmount() {
? this.$refs.container.removeEventListener('scroll', this.handleScroll);
},
methods:{
? //滾輪監(jiān)聽
? handleScroll() {
? ? let listAllHeight =
? ? ? document.documentElement.scrollTop ||
? ? ? document.body.scrollTop + document.documentElement.scrollHeight ||
? ? ? document.body.scrollHeight;
? ? let containerHeight = document.querySelector('#container').scrollHeight;
? ? //46 + 62 + 75是表格距離頁面頂部的剩余距離,跟個(gè)人布局有關(guān)
? ? let fieldHeight = document.querySelector('#left-field').scrollHeight + 46 + 62 + 75;
? ? if (
? ? ? (fieldHeight >= containerHeight && this.pageHeight !== fieldHeight) ||
? ? ? (containerHeight > fieldHeight && this.pageHeight !== containerHeight)
? ? ) {
? ? ? this.visibleLoading = true;
? ? }
? ? setTimeout(() => {
? ? ? if (listAllHeight === this.pageHeight && this.pageHeight < containerHeight) {
? ? ? ? this.pageHeight = this.pageHeight + 750;
? ? ? }
? ? ? if (this.pageHeight > containerHeight && containerHeight > fieldHeight) {
? ? ? ? this.pageHeight = containerHeight;
? ? ? }
? ? ? if (this.pageHeight > fieldHeight && fieldHeight >= containerHeight) {
? ? ? ? this.pageHeight = fieldHeight;
? ? ? }
? ? ? this.visibleLoading = false;
? ? }, 500);
? },
}css
.loading-bottom {
? position: absolute;
? left: 255px;
? bottom: 0;
? height: 30px;
? padding: 5px 0;
? background-color: #d3dae6;
? width: calc(100% - 270px);
? text-align: center;
? font-size: 14px;
? font-weight: 500;
? border-radius: 2px;
}以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue-element-admin 全局loading加載等待
本文主要介紹了vue-element-admin 全局loading加載等待,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
vue用ant design中table表格,點(diǎn)擊某行時(shí)觸發(fā)的事件操作
這篇文章主要介紹了vue用ant design中table表格,點(diǎn)擊某行時(shí)觸發(fā)的事件操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-10-10
vue2 el-checkbox-group復(fù)選框無法選中問題及解決
這篇文章主要介紹了vue2 el-checkbox-group復(fù)選框無法選中問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
vue+moment實(shí)現(xiàn)倒計(jì)時(shí)效果
這篇文章主要為大家詳細(xì)介紹了vue+moment實(shí)現(xiàn)倒計(jì)時(shí)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08
Vue3中ref和reactive的基本使用及區(qū)別詳析
這篇文章主要給大家介紹了關(guān)于Vue3中ref和reactive的基本使用及區(qū)別的相關(guān)資料,需要的朋友可以參考下2022-07-07
Vue-cli Eslint在vscode里代碼自動(dòng)格式化的方法
本篇文章主要介紹了Vue-cli Eslint在vscode里代碼自動(dòng)格式化的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02

