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
docs: add custom fetch composable example #20115
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
β Live Preview ready!
|
6dbbc79
to
3a7f42b
Compare
2014a10
to
9baf841
Compare
} | ||
|
||
// for nice deep defaults, please use unjs/defu | ||
const params = Object.assign(defaults, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice idea! let's go ahead and use defu then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated :)
if (userAuth.value) { | ||
options.headers.Authorization = `Bearer ${userAuth.value}` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might also need to handle the case where this is a Headers
object and we need to do headers.set()
. For simplicity, is there any reason not to use the headers: {}
option directly instead of within onRequest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried something simpler :)
examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts
Outdated
Show resolved
Hide resolved
examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts
Outdated
Show resolved
Hide resolved
examples/other/use-custom-fetch-composable/composables/useCustomFetch.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
should we close #14736 ? |
We also need to add some composables for modifying the inner behaviour of the data fetching composables, much as we have defineNuxtLink. |
π Linked issue
#14736
β Type of change
π Description
Adds an example in the
other
folder of custom use fetch composable. It handles default values and auth but can be overriden.π Checklist