From 93d60a30de31493ba79d29d506848ee5131183e6 Mon Sep 17 00:00:00 2001 From: mrauhu Date: Wed, 6 Jul 2022 22:17:59 +0300 Subject: [PATCH] feat(nuxt): allow passing custom fetch options to `useFetch` (#5660) --- packages/nuxt/src/app/composables/fetch.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index 2d52a096ec..4d94093e5c 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -38,16 +38,32 @@ export function useFetch< return (isRef(r) ? r.value : r) as NitroFetchRequest }) + const { + server, + lazy, + default: defaultFn, + transform, + pick, + watch, + initialCache, + ...fetchOptions + } = opts + const _fetchOptions = { - ...opts, + ...fetchOptions, cache: typeof opts.cache === 'boolean' ? undefined : opts.cache } const _asyncDataOptions: AsyncDataOptions<_ResT, Transform, PickKeys> = { - ...opts, + server, + lazy, + default: defaultFn, + transform, + pick, + initialCache, watch: [ _request, - ...(opts.watch || []) + ...(watch || []) ] }