vue.js 分页加载,向上滑动,依次加载数据。

export default {
    layout: 'default',
    data(){
      return{
        page:1,
        pageSize:10,
        orderListArr:[],
        prodListLoadingOver:false,
        prodListLastPage: false,
      }
    },
    mounted(){
      window.addEventListener('scroll', this.handleScroll);
    },
    created(){
      this.fetchOrderListAction();
    },
    methods:{
      fetchOrderListAction(){
        let reqBody = {};
        reqBody.page = this.page;
        reqBody.pageSize = this.pageSize;
        this.prodListLoadingOver = false;
        fetchOrderList(JSON.stringify(reqBody)).then((res) => {
          let resData = res.data;
          if (resData.respHeader && resData.respHeader.resultCode === 0) {
            this.prodListLoadingOver = true;
            this.orderListArr = resData.respBody.subsList;
            if(this.page == 1){
              this.orderListArr = resData.respBody.subsList;
            }else{
              this.orderListArr = this.orderListArr.concat(resData.respBody.subsList);
            }
            if(resData.respBody.subsList.length < this.pageSize){
              this.prodListLastPage = true;
            }
          }else{
            Toast({
              message: resData.respHeader.message || "网络异常",
            });
          }
        });
      },
      handleScroll(){
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        let h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; //屏幕的高度
        let prodListHeight = document.querySelector('.myOrderListWrapper').offsetHeight-h-20;  //.myOrderListWrapper 商品列表容器
        console.log(scrollTop,":::",prodListHeight)
        if(scrollTop > prodListHeight && this.prodListLoadingOver && !this.prodListLastPage){
          this.page = this.page + 1;
          this.fetchOrderListAction();
        }
      },
    },
    destroyed(){
      window.removeEventListener('scroll', this.handleScroll);
    }
  }

 

在mounted中注册滚动事件,在destroyed中销毁。。。其他鼠标事件也是如此。
 
 

 

转载于:https://www.cnblogs.com/ilovexiaoming/p/11015213.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值