vue如何实现纯前端表格滚动分页加载
导读:本文共1191.5字符,通常情况下阅读需要4分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 实现效果实现过程<divid="container"ref="container"@mousewheel="handleScroll":><!--表格--><divclass="loading-bottom"v-show="vis... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。实现效果
实现过程
<divid="container"ref="container"@mousewheel="handleScroll":><!--表格--><divclass="loading-bottom"v-show="visibleLoading"><a-spin:spinning="visibleLoading"></a-spin>正在加载数据</div></div>
data(){return{visibleLoading:false,}},mounted(){//ref指向对应div,不建议对window全局监听,会影响子div的滚动this.$refs.container.addEventListener('scroll',this.handleScroll);},beforeUnmount(){this.$refs.container.removeEventListener('scroll',this.handleScroll);},methods:{//滚轮监听handleScroll(){letlistAllHeight=document.documentElement.scrollTop||document.body.scrollTop+document.documentElement.scrollHeight||document.body.scrollHeight;letcontainerHeight=document.querySelector('#container').scrollHeight;//46+62+75是表格距离页面顶部的剩余距离,跟个人布局有关letfieldHeight=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);},}
.loading-bottom{position:absolute;left:255px;bottom:0;height:30px;padding:5px0;background-color:#d3dae6;width:calc(100%-270px);text-align:center;font-size:14px;font-weight:500;border-radius:2px;}
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
vue如何实现纯前端表格滚动分页加载的详细内容,希望对您有所帮助,信息来源于网络。