Vue 实现滚动加载

Vue 实现滚动加载

data(){
    
       
	return {
    
    
		page:1,
		categoryList:[],
     	isLoading:false//防止多次请求
      }
},
mounted(){
    
    
	this.scroll()
},
 methods:{
    
    
      scroll() {
    
    
          window.addEventListener("scroll", ()=>{
    
    
          // 距离底部200px时加载一次
              let bottomOfWindow = document.documentElement.offsetHeight - document.documentElement.scrollTop - window.innerHeight <= 200;
              if (bottomOfWindow && this.isLoading == false) {
    
    
                  this.isLoading = true
                  this.page++
                  render(this.page);//请求方法
              }
          })
      },
  }

猜你喜欢

转载自blog.csdn.net/qq_58648235/article/details/130221014