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() +})