JS节流代码


        // JS节流
        onLoad(data) { 
            let that=this
            // 节流操作
            var throttle = function(){            
                var timer = null;            
                return function() {                           
                    if (!timer) {                    
                        timer = setTimeout(function() {    
                            window.callSvc( 'appWorkorderSearch.getApplyWorkorderList',that.getParams({}),(ok, rslt, ext)=>{  
                                // 加载状态结束
                                that.loading = false;
                                if(ok){     
                                    // // 数据全部加载完成
                                    if (that.list!==undefined && that.list.length >= rslt.count){ 
                                        that.finished = true;
                                    }else{
                                        // 加载状态结束
                                        that.finished = false;
                                        that.list.push(...rslt.list)
                                        that.start=10+that.start 
                                        that.paging.limit+=10  
                                    } 
                                    timer = null;    
                                }else{ 
                                    Toast(ext[Object.keys(ext)[0]])  
                                }
                            })                         
                        }, 500);                
                    }            
                }        
            }
            throttle()()   
        }, 
发布了22 篇原创文章 · 获赞 25 · 访问量 3119

猜你喜欢

转载自blog.csdn.net/lys20000913/article/details/103973993
今日推荐