项目中有一个表格  , 用原生table写的 , 要做下拉加载功能 , 原理就是当屏幕滚到底部时 , 把pageNo++  , 再触发一次请求数据 , 把请求回来的下一页数据合并到前一页数组中 this.list = this.list.concat(data);

created() {
      window.addEventListener('scroll', this.Scrollbottom);  //页面加载时监听滚动事件
   },

destroyed() {
      window.removeEventListener('scroll', this.Scrollbottom) //页面离开后销毁监听事件
   },



// methods中 
Scrollbottom() {
        let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        let clientHeight = document.documentElement.clientHeight;
        let scrollHeight = document.documentElement.scrollHeight;
        if (scrollTop + clientHeight >= scrollHeight) {
          console.log("滚动到底部了")
          this.pageNo++
          console.log(this.pageNo);
          this.fetchData()

        }
},

Logo

前往低代码交流专区

更多推荐