Skip to content

Instantly share code, notes, and snippets.

@Fanreza
Created August 17, 2023 11:38
Show Gist options
  • Save Fanreza/c2d5282d8d4a12d79e89f00a9b118d32 to your computer and use it in GitHub Desktop.
Save Fanreza/c2d5282d8d4a12d79e89f00a9b118d32 to your computer and use it in GitHub Desktop.
Nuxt composable useFetch with global options and interceptors
import { useFetch } from "#app";
type useFetchType = typeof useFetch;
export const useHttp: useFetchType = (path, options = {}) => {
const config = useRuntimeConfig();
options.baseURL = config.public.baseUrl;
options.onResponseError = (error) => {};
return useFetch(path, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment