Skip to content

How to prevent useFetch from refreshing data on navigation #27006

Answered by cmgdragon
meirroth asked this question in Questions
Discussion options

You must be logged in to vote

ok, I see,

maybe making the query object reactive could work

const query = reactive({ dir: true })

const { data } = await useFetch('https://icanhazdadjoke.com', {
  headers: { Accept: 'application/json' },
  query,
  getCachedData(key) {
    return nuxtApp.payload.data[key] || nuxtApp.static.data[key];
  },
})

function toggleDir() {
  query.dir = !query.dir
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@meirroth
Comment options

@cmgdragon
Comment options

Answer selected by meirroth
@meirroth
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants