question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useAsyncData can‘t watch slug

See original GitHub issue

Environment


  • Operating System: Darwin
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0-rc.2
  • Package Manager: pnpm@6.23.6
  • Builder: vite
  • User Config: modules, experimental, unocss, colorMode
  • Runtime Modules: @vueuse/nuxt@8.3.1, @unocss/nuxt@0.32.9, @pinia/nuxt@0.1.8, @nuxtjs/color-mode@3.0.2
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-wp5lsq-fyzsuf?file=pages/[slug].vue

Describe the bug

useAsyncData cannot update data correctly when watch slugs

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
manniLcommented, Nov 4, 2022

@sangyookim-ogq kindly create a new issue instead of replying to old closed ones ☺️ (Feel free to link this one in your new issue though). And please provide a reproduction!

0reactions
sangyookmcommented, Nov 4, 2022
async setup() {
    const route = useRoute()
    const {data: noticeData} = useAsyncData(
      ()=> $fetch('/api/notice/single', {
        method: 'get',
        headers: useRequestHeaders(['cookie']),
        params: {
          noticeId: route.params.noticeId
        }
      }, {
        initialCache: false,
        watch: [route]
      })
    )
    return {
      noticeData
    }
  }

My data wont refresh after the first time.

PageA -> PageB[AsyncData with param 1| Works] -> Back button to Page A -> PageB[AsyncData with param2| stuck in param 1 data]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt V3 getByUID trying to get documents from prismic but won't ...
const { data: proyecto } = await useAsyncData(slug, () => client.getByUID('proyecto', slug)) ... I can't see a UID field in your custom types...
Read more >
Nuxt dynamic page slug not changing in asyncdata
In a project I'm working on I have a dynamic page in pages/news/_slug.vue. I use the asyncData hook to fetch the data that...
Read more >
Data Fetching - Nuxt
In Nuxt we have 2 ways of getting data from an API. We can use the fetch method or the asyncData method. Nuxt...
Read more >
Understanding Difference Between Asyncdata Fetch Nuxt
Nuxt provides two useful hooks for fetching data: AsyncData and Fetch. They're available at different times in the Nuxt lifecycle, ...
Read more >
Nuxt3 doesn't fetch new data after client-side navigation : r/Nuxt
Isn't the slug page component always destroyed after navigation ... Can't believe Next.js founder said my open source project is 'fantastic'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found