From aa73cbeaf91766c5091cab59b18a9b00fba2e831 Mon Sep 17 00:00:00 2001 From: Maxime Pauvert Date: Mon, 11 Sep 2023 10:14:01 +0200 Subject: [PATCH] fix(nuxt): include method when creating `useFetch` auto key (#23086) --- packages/nuxt/src/app/composables/fetch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index e70a1d6907..7e6371b2f7 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -1,6 +1,6 @@ import type { FetchError, FetchOptions } from 'ofetch' import type { NitroFetchRequest, TypedInternalResponse, AvailableRouterMethod as _AvailableRouterMethod } from 'nitropack' -import type { Ref } from 'vue' +import type { MaybeRef, Ref } from 'vue' import { computed, reactive, unref } from 'vue' import { hash } from 'ohash' import { useRequestFetch } from './ssr' @@ -85,7 +85,7 @@ export function useFetch< return unref(r) }) - const _key = opts.key || hash([autoKey, unref(opts.baseURL), typeof _request.value === 'string' ? _request.value : '', unref(opts.params || opts.query)]) + const _key = opts.key || hash([autoKey, unref(opts.method as MaybeRef | undefined)?.toUpperCase() || 'GET', unref(opts.baseURL), typeof _request.value === 'string' ? _request.value : '', unref(opts.params || opts.query)]) if (!_key || typeof _key !== 'string') { throw new TypeError('[nuxt] [useFetch] key must be a string: ' + _key) }