记一次懒加载

        get_indet_list(id){
             commonApi.getIndetList(query).then(res=>{
                this.loading = false;
                let indetList = res.datalist;
                this.total = res.total;
                this.pags_info.total = res.total;
                
                this.indetList = [...this.indetList,...indetList];  // 拼接数据
                if(this.total == this.indetList.length){ // 停止加载
                    window.removeEventListener('scroll', this.scroll, true);
                    return false;
                }
                window.addEventListener('scroll', this.scroll, true);// 开始监听滚动条,准备加载数据
        }
        scroll(){
            // 滚动鼠标触发
            let scrollTop = document.documentElement.scrollTop;
            let clientHeight = document.documentElement.clientHeight
            let scrollHeight = document.documentElement.scrollHeight;
            let h = scrollHeight-scrollTop-clientHeight;
            
            
            if(this.total > this.indetList.length && h <= 80) {
                this.loading = true;
                this.pags_info.page++;
                this.get_indet_list();
                window.removeEventListener('scroll', this.scroll, true);
            }
        }

 

posted @ 2020-07-31 15:30  靖哥哥~  阅读(93)  评论(0)    收藏  举报