经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » Vue.js » 查看文章
vue实现纯前端表格滚动分页加载
来源:jb51  时间:2022/4/11 16:15:59  对本文有异议

本文实例为大家分享了vue实现表格滚动分页加载的具体代码,供大家参考,具体内容如下

实现效果

实现过程

  1. <div
  2. ? ? style="width: 100%; overflow: hidden; position: relative"
  3. ? ? id="container"
  4. ? ? ref="container"
  5. ? ? @mousewheel="handleScroll"
  6. ? ? :style="{ height: pageHeight + 'px' }">
  7. ? <!-- ? ?表格-->
  8. ? <div class="loading-bottom" v-show="visibleLoading">
  9. ? ? ? <a-spin :spinning="visibleLoading" style="margin-right: 10px"></a-spin>正在加载数据
  10. ? ? </div>
  11. </div>

js

  1. data() {
  2. ? return {
  3. ? ? visibleLoading: false,
  4. ? }
  5. },
  6. mounted() {
  7. ? //ref指向对应div,不建议对window全局监听,会影响子div的滚动
  8. ? this.$refs.container.addEventListener('scroll', this.handleScroll);
  9. },
  10. beforeUnmount() {
  11. ? this.$refs.container.removeEventListener('scroll', this.handleScroll);
  12. },
  13. methods:{
  14. ? //滚轮监听
  15. ? handleScroll() {
  16. ? ? let listAllHeight =
  17. ? ? ? document.documentElement.scrollTop ||
  18. ? ? ? document.body.scrollTop + document.documentElement.scrollHeight ||
  19. ? ? ? document.body.scrollHeight;
  20. ? ? let containerHeight = document.querySelector('#container').scrollHeight;
  21. ? ? //46 + 62 + 75是表格距离页面顶部的剩余距离,跟个人布局有关
  22. ? ? let fieldHeight = document.querySelector('#left-field').scrollHeight + 46 + 62 + 75;
  23. ? ? if (
  24. ? ? ? (fieldHeight >= containerHeight && this.pageHeight !== fieldHeight) ||
  25. ? ? ? (containerHeight > fieldHeight && this.pageHeight !== containerHeight)
  26. ? ? ) {
  27. ? ? ? this.visibleLoading = true;
  28. ? ? }
  29.  
  30. ? ? setTimeout(() => {
  31. ? ? ? if (listAllHeight === this.pageHeight && this.pageHeight < containerHeight) {
  32. ? ? ? ? this.pageHeight = this.pageHeight + 750;
  33. ? ? ? }
  34. ? ? ? if (this.pageHeight > containerHeight && containerHeight > fieldHeight) {
  35. ? ? ? ? this.pageHeight = containerHeight;
  36. ? ? ? }
  37. ? ? ? if (this.pageHeight > fieldHeight && fieldHeight >= containerHeight) {
  38. ? ? ? ? this.pageHeight = fieldHeight;
  39. ? ? ? }
  40. ? ? ? this.visibleLoading = false;
  41. ? ? }, 500);
  42. ? },
  43. }

css

  1. .loading-bottom {
  2. ? position: absolute;
  3. ? left: 255px;
  4. ? bottom: 0;
  5. ? height: 30px;
  6. ? padding: 5px 0;
  7. ? background-color: #d3dae6;
  8. ? width: calc(100% - 270px);
  9. ? text-align: center;
  10. ? font-size: 14px;
  11. ? font-weight: 500;
  12. ? border-radius: 2px;
  13. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号