vue.js滚动条下拉,数据重复渲染

新手上路,请多包涵

get_productsList:function(){

            // 缓存指针
            var _this=this;
            // 设置一个开关来避免重负请求数据
              let sw = true;
            let adrObj = {
                'path': misslove.path,
                'page':1
            }
            console.log(adrObj)
            this.$http.post(misslove.host+"/index.php?route=product/category/get_products",adrObj,{emulateJSON:true}).then(
                function (res) {
                    // 处理成功的结果
                    console.log(res.data)
                    var re = res.data;
                    if(re.code=="200"){
                        _this.products= re.products;
                    }
                },function (err) {
                    // 处理失败的结果
                    console.log(err)
          });
             let isLoading = false
                window.onscroll = () => {
                // 距离底部200px时加载一次
                    let bottomOfWindow = document.documentElement.offsetHeight - document.documentElement.scrollTop - window.innerHeight <= 200  
                       if (bottomOfWindow && isLoading == false) {
                            // 将开关关闭
                           isLoading = true
                           
               this.$http.post(misslove.host+"/index.php?route=product/category/get_products",{'path': misslove.path,'page':page++},{emulateJSON:true}).then(
                function (res) {
                    console.log(res)
                    //数据重复位置
                    var pists  = res.data.products;
                      if (!pists) pists = [];
                      var $arr = _this.products;
                      for (let i = 0; i < pists.length; i++) {
                        if (pists[i].Access != 0) {
                         $arr.push(pists[i]);

// _this.products.push(pists[i])

                        }
                    }
                      _this.products = $arr;
                      console.log(_this.products)
                      
                },function (err) {
                    // 处理失败的结果
                    console.log(err)
                    });

                // 数据更新完毕,将开关打开
                           isLoading = false
                       }
                  }
        },

数据一共有26条,一页显示20条,现在res这里先渲染出来20条再渲染出来6条,又重复渲染了20条 ,数据重复、?????

阅读 2.4k
1 个回答

push是往里面追加,在下拉的时候先清空数组,在push 每次下拉触发一次清空就行了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题