fix(nuxt): include method when creating useFetch auto key (#23086)

This commit is contained in:
Maxime Pauvert 2023-09-11 10:14:01 +02:00 committed by GitHub
parent 48fa30af92
commit aa73cbeaf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import type { FetchError, FetchOptions } from 'ofetch' import type { FetchError, FetchOptions } from 'ofetch'
import type { NitroFetchRequest, TypedInternalResponse, AvailableRouterMethod as _AvailableRouterMethod } from 'nitropack' 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 { computed, reactive, unref } from 'vue'
import { hash } from 'ohash' import { hash } from 'ohash'
import { useRequestFetch } from './ssr' import { useRequestFetch } from './ssr'
@ -85,7 +85,7 @@ export function useFetch<
return unref(r) 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<string | undefined> | undefined)?.toUpperCase() || 'GET', unref(opts.baseURL), typeof _request.value === 'string' ? _request.value : '', unref(opts.params || opts.query)])
if (!_key || typeof _key !== 'string') { if (!_key || typeof _key !== 'string') {
throw new TypeError('[nuxt] [useFetch] key must be a string: ' + _key) throw new TypeError('[nuxt] [useFetch] key must be a string: ' + _key)
} }