fix(buyer): 修复商品列表路由变化时重复请求

- $route watcher 中 handleSearch 与末尾兜底调用重叠,带 keyword 时同一请求发两次,改为互斥分支
- 修复从关键词搜索切换到分类/促销路由时 params.keyword 残留旧值的问题
This commit is contained in:
pikachu1995@126.com
2026-10-09 09:50:38 +08:00
parent b639bc36eb
commit 1bd50cee45

View File

@@ -142,22 +142,25 @@ export default {
},
watch: {
$route() {
const keyword = this.$route.query.keyword;
if (keyword) {
this.handleSearch(keyword);
}
if (this.$route.query.categoryId) {
let cateId = this.$route.query.categoryId.split(",");
const { keyword, categoryId, promotionType, promotionsId } = this.$route.query;
if (categoryId) {
const cateId = categoryId.split(",");
Object.assign(this.params, this.$route.query);
this.params.categoryId = cateId[cateId.length - 1];
}
if (this.$route.query.promotionType) {
this.params.promotionType = this.$route.query.promotionType;
if (promotionType) {
this.params.promotionType = promotionType;
}
if (this.$route.query.promotionsId) {
this.params.promotionsId = this.$route.query.promotionsId;
if (promotionsId) {
this.params.promotionsId = promotionsId;
}
if (keyword) {
// handleSearch 内部会调 getGoodsList,此处不再重复请求
this.handleSearch(keyword);
} else {
this.params.keyword = "";
this.getGoodsList();
}
this.getGoodsList();
},
},
computed: {