Skip to content

How to set default baseURL for useFetch? #15930

Answered by Megarsh
and2 asked this question in Questions
Discussion options

You must be logged in to vote

I've been using a composable to create localized fetch requests, so in your case you can do something like this

Add this composable
export const useBaseFetch = (url, options = {}) => $fetch(`/base-url${url}`, options)

And use it like this
const { data } = await useAsyncData('key', () => useBaseFetch('/data'))

Replies: 6 comments 12 replies

Comment options

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

@Y-anon
Comment options

@ArmanHashemi
Comment options

Answer selected by and2
Comment options

You must be logged in to vote
2 replies
@manniL
Comment options

@mukundshah
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Disservin
Comment options

Comment options

You must be logged in to vote
5 replies
@Disservin
Comment options

@manniL
Comment options

@Disservin
Comment options

@Disservin
Comment options

@laventnc
Comment options

Comment options

You must be logged in to vote
1 reply
@Disservin
Comment options

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