MCPcopy
hub / github.com/vueuse/vueuse / useFactoryFetch

Function useFactoryFetch

packages/core/useFetch/index.ts:281–328  ·  view source on GitHub ↗
(url: MaybeRefOrGetter<string>, ...args: any[])

Source from the content-addressed store, hash-verified

279 const _fetchOptions = config.fetchOptions || {}
280
281 function useFactoryFetch(url: MaybeRefOrGetter<string>, ...args: any[]) {
282 const computedUrl = computed(() => {
283 const baseUrl = toValue(config.baseUrl)
284 const targetUrl = toValue(url)
285
286 return (baseUrl && !isAbsoluteURL(targetUrl))
287 ? joinPaths(baseUrl, targetUrl)
288 : targetUrl
289 })
290
291 let options = _options
292 let fetchOptions = _fetchOptions
293
294 // Merge properties into a single object
295 if (args.length > 0) {
296 if (isFetchOptions(args[0])) {
297 options = {
298 ...options,
299 ...args[0],
300 beforeFetch: combineCallbacks(_combination, _options.beforeFetch, args[0].beforeFetch),
301 afterFetch: combineCallbacks(_combination, _options.afterFetch, args[0].afterFetch),
302 onFetchError: combineCallbacks(_combination, _options.onFetchError, args[0].onFetchError),
303 }
304 }
305 else {
306 fetchOptions = {
307 ...fetchOptions,
308 ...args[0],
309 headers: {
310 ...(headersToObject(fetchOptions.headers) || {}),
311 ...(headersToObject(args[0].headers) || {}),
312 },
313 }
314 }
315 }
316
317 if (args.length > 1 && isFetchOptions(args[1])) {
318 options = {
319 ...options,
320 ...args[1],
321 beforeFetch: combineCallbacks(_combination, _options.beforeFetch, args[1].beforeFetch),
322 afterFetch: combineCallbacks(_combination, _options.afterFetch, args[1].afterFetch),
323 onFetchError: combineCallbacks(_combination, _options.onFetchError, args[1].onFetchError),
324 }
325 }
326
327 return useFetch(computedUrl, fetchOptions, options)
328 }
329
330 return useFactoryFetch as typeof useFetch
331}

Callers

nothing calls this directly

Calls 6

isAbsoluteURLFunction · 0.85
joinPathsFunction · 0.85
isFetchOptionsFunction · 0.85
combineCallbacksFunction · 0.85
headersToObjectFunction · 0.85
useFetchFunction · 0.70

Tested by

no test coverage detected