From 746db18c59bb3ab00fc1bd1f454f170a19a60240 Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 18 Apr 2025 16:43:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(ProductList):=20=E5=9C=A8=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E5=88=B7=E6=96=B0=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 确保在路由更新到ProductList时重新获取产品数据,以保持页面数据的同步和准确性 --- src/pages/product/ProductList.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pages/product/ProductList.vue b/src/pages/product/ProductList.vue index 1e14c71..c97a9f6 100644 --- a/src/pages/product/ProductList.vue +++ b/src/pages/product/ProductList.vue @@ -8,6 +8,7 @@ import VanPopup from "vant/es/popup" import { computed, onBeforeUnmount, onMounted, ref } from "vue" import Cart from "./components/cart.vue" import Detail from "./components/detail.vue" +import { onBeforeRouteUpdate } from 'vue-router' // 状态管理 const productStore = useProductStore() @@ -102,6 +103,7 @@ const currentProducts = computed(() => { // 组件挂载时添加滚动监听 onMounted(() => { + productStore.getGoods(); scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledScroll)) scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledUpdate)) }) @@ -118,6 +120,14 @@ const router = useRouter() function handleCheckout() { router.push("/product/checkout") } + +// 路由更新时刷新数据 +onBeforeRouteUpdate((to, from, next) => { + if (to.name == 'ProductList') { + productStore.getGoods() + } + next() +})