谢谢大家回答请问我这段下拉加载更多的代码,怎样搭配搜索去做?

get_goods_shop_list({        
                    cat_id:this.cat_id,
                    brand_id:this.bid,
                    keyword:this.keyword,
                    warehouse_id:this.warehouse_id,
                    price_rank:this.price_id,
                    page:this.page,
                    size:10
                    
                }).then(res=>{
                    console.log(res,'商品李北奥')
                    let data = res.data.data
                    this.shop_data = this.shop_data.concat(data.list)
                
                    
                    this.total = res.data.data.total
                    console.log(this.shop_data,898)
                })

上面这段是请求成功 拿到的数据,this.shop_data是我渲染的列表数据,这时候下拉加载更多是没问题的,
但是当我调用了下面这段搜索代码的时候,后端返回的数据已经是搜索结果的数据,但是页面上显示的数据没变化,我感觉是要清空下, 重新获取,但是好像又会影响加载更多的功能,不知道怎么去改,想让大家帮忙看看
search_click(){

            console.log(22233)        
            this.get_shop_list() //这是上面的方法 重新调用了下,里面的keyword已经取到了,
        },
阅读 1.1k
1 个回答

搜索时肯定是要清空的

// 首次渲染时调用
mounted(){
  this.get_shop_list()
}

// 点击搜索时
onSearch(keyword){
  this.page = 1; // 到初始页
  this.keyword=keyword;
  this.shop_data = []
  this.get_shop_list()
}

//上拉加载时
onScroll(){
  this.page++; // 这里还需判断page是否已经大于最大页数,要和              Math.ceil(total/10)对比一下
  this.get_shop_list()
}

这样应该没问题吧

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