fix(ProductList): 在路由更新时刷新产品数据

确保在路由更新到ProductList时重新获取产品数据,以保持页面数据的同步和准确性
This commit is contained in:
dzq 2025-04-18 16:43:51 +08:00
parent 2d502e6bb1
commit 746db18c59
1 changed files with 10 additions and 0 deletions

View File

@ -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()
})
</script>
<template>