react 中如如何实现上拉加载事件

Posted ximenchuifa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react 中如如何实现上拉加载事件相关的知识,希望对你有一定的参考价值。

文档上卷的距离+窗口的高度=文档的距离 就可以说到底了 但是我们往往在还未到低时候就开始加载下一页

//添加窗口滚动事件
    window.onscroll = () => {
      //上卷距离 
      let st = document.documentElement.scrollTop || document.body.scrollTop;
      //窗口高度
      let wh = document.documentElement.clientHeight;
      //文档高度
      let dh = document.documentElement.offsetHeight;
      if(st+wh+50>=dh&&this.isRequst){//到底了
        this.isRequst=false;
        console.log("到底了");
        this.n++;
        let times=this.getTime(this.n)
        //发请求 
        axios({url:"/api/4/stories/before/"+times.reqTime}).then(res=>{
          this.setState({
            list:[
              ...this.state.list,
              {
                time:times.showTime,
                data:res.data.stories
              }
            ]
          },()=>{
            this.isRequst=true
            console.log(this.state.list);
          })
        })
      }
    }
  }

 

以上是关于react 中如如何实现上拉加载事件的主要内容,如果未能解决你的问题,请参考以下文章

Android RecyclerView上拉加载更多item点击事件(显示获取的数据)

移动端touch事件 || 上拉加载更多

JQuery代码实现上拉加载

如何实现Swift快速集成下拉刷新和上拉加载更多

小程序_上拉加载更多

H5下拉刷新和上拉加载实现原理浅析