文檔上卷的距離+窗口的高度=文檔的距離 就可以說到底了 但是我們往往在還未到低時候就開始加載下一頁
//添加窗口滾動事件 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); }) }) } } }