fix(ProductList): 在路由更新时刷新产品数据
确保在路由更新到ProductList时重新获取产品数据,以保持页面数据的同步和准确性
This commit is contained in:
parent
2d502e6bb1
commit
746db18c59
|
@ -8,6 +8,7 @@ import VanPopup from "vant/es/popup"
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue"
|
import { computed, onBeforeUnmount, onMounted, ref } from "vue"
|
||||||
import Cart from "./components/cart.vue"
|
import Cart from "./components/cart.vue"
|
||||||
import Detail from "./components/detail.vue"
|
import Detail from "./components/detail.vue"
|
||||||
|
import { onBeforeRouteUpdate } from 'vue-router'
|
||||||
|
|
||||||
// 状态管理
|
// 状态管理
|
||||||
const productStore = useProductStore()
|
const productStore = useProductStore()
|
||||||
|
@ -102,6 +103,7 @@ const currentProducts = computed(() => {
|
||||||
|
|
||||||
// 组件挂载时添加滚动监听
|
// 组件挂载时添加滚动监听
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
productStore.getGoods();
|
||||||
scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledScroll))
|
scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledScroll))
|
||||||
scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledUpdate))
|
scrollListener.push(scrollContainer.value?.addEventListener("scroll", throttledUpdate))
|
||||||
})
|
})
|
||||||
|
@ -118,6 +120,14 @@ const router = useRouter()
|
||||||
function handleCheckout() {
|
function handleCheckout() {
|
||||||
router.push("/product/checkout")
|
router.push("/product/checkout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 路由更新时刷新数据
|
||||||
|
onBeforeRouteUpdate((to, from, next) => {
|
||||||
|
if (to.name == 'ProductList') {
|
||||||
|
productStore.getGoods()
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in New Issue