feat(nuxt): allow passing custom fetch options to useFetch (#5660)

This commit is contained in:
mrauhu 2022-07-06 22:17:59 +03:00 committed by GitHub
parent b5f5f7d5ba
commit 93d60a30de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,16 +38,32 @@ export function useFetch<
return (isRef(r) ? r.value : r) as NitroFetchRequest return (isRef(r) ? r.value : r) as NitroFetchRequest
}) })
const {
server,
lazy,
default: defaultFn,
transform,
pick,
watch,
initialCache,
...fetchOptions
} = opts
const _fetchOptions = { const _fetchOptions = {
...opts, ...fetchOptions,
cache: typeof opts.cache === 'boolean' ? undefined : opts.cache cache: typeof opts.cache === 'boolean' ? undefined : opts.cache
} }
const _asyncDataOptions: AsyncDataOptions<_ResT, Transform, PickKeys> = { const _asyncDataOptions: AsyncDataOptions<_ResT, Transform, PickKeys> = {
...opts, server,
lazy,
default: defaultFn,
transform,
pick,
initialCache,
watch: [ watch: [
_request, _request,
...(opts.watch || []) ...(watch || [])
] ]
} }