Nuxt 3 dynamic page changes URL but content remains the same and data is only fetched once
P粉476883986
P粉476883986 2023-11-03 14:39:04
0
1
610

I have aproducts/indexpage withproducts/[slug]in the main product page and I have aNuxtLinkto change the page and go toproducts/[slug]and get the data for that product.

On the first click, I have the correct data, but when I click back or click on the product/index page and then try to click on another product, I have the first product I clicked on and the information for each product, Again I got the information for the first product I clicked on.

Usingconsole.logallowed me to find that my fetched datahas not changed, am I missing something here?

Using:key and :page-keyondoes not work.

The first product I clicked

The second product is still unchanged, the data comes from the first product

The third picture is still unchanged

productComponent.vue

 

products/index.vuePage

 

product/[slug]

  


P粉476883986
P粉476883986

reply all (1)
P粉759457420

I found the solution I have to add a parameter

in useFetch
const {data: productData, pending, refresh, error} = await useFetch(`http://127.0.0.1:8000/api/products/${slug}` , { initialCache: false })

Because the api caches and will not send another request, useinitialCache : falseit will send another request This way works fine for main product, but in products/[slug] or blog/[slug] I think you have to do this, if you have a better way please leave me a comment

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!