谢谢大家回答请问我这段下拉加载更多的代码,怎样搭配搜索去做?
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个回答

test
2024-07-20
搜索时肯定是要清空的
// 首次渲染时调用
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()
}
这样应该没问题吧
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容