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.

useLazyFetch with useRoute query not work

See original GitHub issue

Environment

useLazyFetch

Reproduction

useLazyFetch

Describe the bug

there is a Pagination component

<template>
  <div class="tw-flex tw-flex-wrap tw-justify-between">
    <div class="tw-flex tw-items-center">
      <div class="tw-flex">
        <nuxt-link v-for="(page, index) in pageCount" :key="index"
          :class="[activePageNumber == page ? 'tw-bg-default-600 tw-text-white': 'tw-bg-transparent']"
          :to="`${link}?page=${page}`"
          class="tw-py-2 tw-px-3 tw-mr-2 tw-rounded tw-cursor-pointer tw-inline-block tw-h-8 tw-text-center"
        >{{ page }}
        </nuxt-link>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useRoute } from '#app';
import { computed } from '#imports';

const props = defineProps({
  params: {
    type: Object,
    required: true
  }
});

const route = useRoute();

const link = computed(() => {
  return route.path;
});

const pageCount = computed(() => {
  return Math.ceil(props.params.total / props.params.take);
});

const activePageNumber = computed(() => {
  return route.query.page ?? 1;
});

</script>

My page

const route = useRoute();

const params = reactive({
  skip: 0,
  take: 4
});

const meta = reactive({
  skip: 0,
  take: 4,
  total: 0
});

if (route.query?.page) params.skip = route.query?.page;

const {
  pending,
  data:excursions
} =
  repositoryService.repository.getExcursionsByPaginate(params);

After clicking on pagination links, substitution in useLazyFetch route.query.page does not work

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lucassiminescommented, Aug 4, 2022

useLazyFetch seems not regenating a key for each request, all my useLazyFetch calls returns the same response of the first call.

1reaction
rvmourikcommented, Aug 3, 2022

I have something related, when I use the route.name in a computed variable OR use the route(.name) in a watch function it doesn’t get triggered after navigating.

When I output the $route.name in the template tag, this does get updated after navigating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useRoute · Nuxt Composables
The useRoute composable returns the current route and must be called in a setup function, plugin, or route middleware. Within the template of...
Read more >
Route query is undefined when using useRoute() in setup() for ...
However, this is not true for strings, which is the reason the searchQuery string is undefined in the log, while the route object...
Read more >
[Solution] NextJS Router Query Not Working in useEffect
A simple example would be something like this: Notice the data is undefined on the console, but it is rendered on the DOM....
Read more >
Nuxt 3 公式ドキュメント 日本語訳 - Zenn
そして、 npm run <command> または yarn <command> を使って各コマンドを実行する ... The requested module 'sample-library' is a CommonJS module, which may not ...
Read more >
Data Fetching - 《Nuxt 3 beta Documentation》 - 书栈网
Nuxt provides useFetch , useLazyFetch , useAsyncData and useLazyAsyncData ... In other words, the async function does not block navigation.
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