diff --git a/packages/shop/index/index.vue b/packages/shop/index/index.vue index 9d31b27a..9d6af476 100644 --- a/packages/shop/index/index.vue +++ b/packages/shop/index/index.vue @@ -135,14 +135,14 @@ - 选择规格 - 收起 @@ -338,17 +338,22 @@ export default { this.topShow = !this.topShow; }, // 选择商品规格 - chooseGG(targetItems) { - // 遍历tagList找到目标对象(排除"全部"选项,从索引1开始) - for (let i = 1; i < this.tagList.length; i++) { - const tagItem = this.tagList[i]; - const infoIndex = tagItem.commodity_info_list.findIndex(item => item.id === targetItems.id); - if (infoIndex > -1) { - // 直接修改数据源中的对象,确保响应式 - const currentItem = tagItem.commodity_info_list[infoIndex]; - this.$set(currentItem, 'isShow', !currentItem.isShow); - console.log("修改后数据源中的isShow:", currentItem.isShow); - break; + chooseGG(item,targetItems) { + // 根据两个参数的id判断点击的数据 + if (item && targetItems && item.id) { + for (let i = 1; i < this.tagList.length; i++) { + const tagItem = this.tagList[i]; + // 先根据item.id找到对应的tagItem + if (tagItem.id === item.id) { + const infoIndex = tagItem.commodity_info_list.findIndex(infoItem => infoItem.id === targetItems.id); + if (infoIndex > -1) { + // 直接修改数据源中的对象,确保响应式 + const currentItem = tagItem.commodity_info_list[infoIndex]; + this.$set(currentItem, 'isShow', !currentItem.isShow); + console.log("修改后数据源中的isShow:", currentItem.isShow); + break; + } + } } } },