Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document query option for useFetch #15368

Closed
manniL opened this issue Nov 4, 2022 · 10 comments · Fixed by nuxt/framework#8719
Closed

Document query option for useFetch #15368

manniL opened this issue Nov 4, 2022 · 10 comments · Fixed by nuxt/framework#8719

Comments

@manniL
Copy link
Member

manniL commented Nov 4, 2022

he documentation does not mention a "query" option, this should be updated and explained across the docs.

_Originally posted by @Aietes in #15359

@manniL manniL changed the title Document query option for useFetch Document query option for useFetch Nov 4, 2022
@eulier1
Copy link

eulier1 commented Nov 4, 2022

After reading the #8692 (comment). For simplicity I would suggest ( and I can do it) to add
query: { [string] : string | Ref<string } to useFetch API .
What do you think?.

@danielroe
Copy link
Member

I believe that the document mentions that the options includes all options that can be passed to fetch, which includes a number of other options that are not mentioned explicitly.

@eulier1
Copy link

eulier1 commented Nov 4, 2022

I'm afraid that is not to be the case, 😔 https://v3.nuxtjs.org/api/composables/use-fetch/

@Aietes
Copy link
Contributor

Aietes commented Nov 5, 2022

The options not mentioned in the docs are inherited from ohmyfetch, that might be the reason they are not mentioned. The problem really is, that one of the main use cases for useFetch, that is using a query string when fetching data, is not accurately reflected in the documentation. I think this should be mentioned in Get Started - Data Fetching, and documented with examples in API - useFetch(). It should appear in the Type description, and more importantly in Params, much like body is documented. In addition an example lower on the page would help. I'm happy to contribute to the docs and write it, if that's possible.

@danielroe
Copy link
Member

That would be great 😊

@Aietes
Copy link
Contributor

Aietes commented Nov 5, 2022

I created a PR for the useFetch API.

I also found the place in the docs which clearly implies writing variables into the API URL should work: Getting Started - Data Fetching.

<script setup>
const page = ref(1);
const { data: users, pending, refresh, error } = await useFetch(() => `users?page=${page.value}&take=6`, { baseURL: config.API_BASE_URL }
);
function previous() {
  page.value--;
  refresh();
}
function next() {
  page.value++;
  refresh();
}
</script>

As per @danielroe this shouldn't work as laid out there, as the API URL will not update necessarily, or am I missing something?

@danielroe
Copy link
Member

That works because the URL is a function.

@Aietes
Copy link
Contributor

Aietes commented Nov 5, 2022

Got it. These are differentiations that are not intuitively clear to the less experienced user (like me).Thank you for the explanation, and all the great work!

Copy link
Member

I think we could do a better job explaining them! Any ideas welcome :-)

@Aietes
Copy link
Contributor

Aietes commented Nov 6, 2022

The Vue.js documentation is really great: lots of explanation and examples, which I believe work great for users. The Nuxt3 documentation is well structured, but could use more of the same type of detailed explanation with more examples in many places. I'm happy to contribute, although I'm not sure if I'm knowledgeable enough.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants