zoukankan      html  css  js  c++  java
  • 笔记-VUE滚动加载更多数据

    来源:https://blog.csdn.net/qq_17281881/article/details/87342403

    VUE滚动加载更多数据

     1 data() {
     2     return {
     3          loading: false,
     4          loadingMore: false,//loading 加载更多
     5          isScroll: true,//是否可以滚动
     6          pageIndex: 1,
     7          pageSize: 10,
     8          list: [],
     9      }
    10  },
    11 
    12 mounted() {
    13     document.addEventListener('scroll', this.scrollMoreData, false)
    14 },
    15 
    16 methods: {
    17     scrollMoreData() {
    18         const scrollTopHeight = document.documentElement.scrollTop || document.body.scrollTop //滚动高度
    19         const clientHeight = document.documentElement.clientHeight || window.screen.availHeight //屏幕可用工作区高度
    20         const offsetHeight = document.documentElement.offsetHeight || document.body.offsetHeight //网页可见区域高(包括边线的宽)
    21         // console.log(scrollTopHeight, clientHeight, scrollTopHeight + clientHeight + 50, offsetHeight)
    22         
    23         if ((scrollTopHeight + clientHeight) + 50 >= offsetHeight && this.isScroll) {
    24             this.isScroll = false
    25             this.loadingMore = true
    26             let pageNo = this.pageIndex += 1
    27             api.Get('/list', {
    28                 pageIndex: pageNo,
    29                 pageSize: this.pageSize,
    30             }).then(res => {
    31                 this.loadingMore = false
    32                 if (res.data.list.length > 0) {
    33                     this.isScroll = true
    34                     this.list = [...this.list, ...res.data.list]
    35                 } else {
    36                     this.show = true
    37                 }
    38             })
    39         }
    40         },
    41     },
    42 },
    43 
    44 destroyed() {
    45     document.removeEventListener('scroll', this.scrollMoreData, false)
  • 相关阅读:
    CrawlSpiders
    从抓取Tencent中学习Scrapy
    对象返回规范的url的两种方式的两种方式
    多对多关系的额外字段
    Django定时任务
    Scripy学习(一)
    Django开发博客一(搭建模型和准备数据)
    求并集
    求子集、交集
    java数学函数Math类中常用的方法
  • 原文地址:https://www.cnblogs.com/laijinquan/p/11107254.html
Copyright © 2011-2022 走看看