This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nuxt): allow
useHead
to accept computed values (#6174)
- Loading branch information
Showing
1 changed file
with
5 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import { isFunction } from '@vue/shared' | ||
import { computed } from 'vue' | ||
import type { ComputedGetter } from '@vue/reactivity' | ||
import type { ComputedGetter, ComputedRef } from '@vue/reactivity' | ||
import type { MetaObject } from '@nuxt/schema' | ||
import { useNuxtApp } from '#app' | ||
|
||
type Computable<T> = T extends Record<string, any> ? ComputedGetter<T> | { [K in keyof T]: T[K] | ComputedRef<T[K]> } : T | ||
|
||
/** | ||
* You can pass in a meta object, which has keys corresponding to meta tags: | ||
* `title`, `base`, `script`, `style`, `meta` and `link`, as well as `htmlAttrs` and `bodyAttrs`. | ||
* | ||
* Alternatively, for reactive meta state, you can pass in a function | ||
* that returns a meta object. | ||
*/ | ||
export function useHead (meta: MetaObject | ComputedGetter<MetaObject>) { | ||
export function useHead (meta: Computable<MetaObject>) { | ||
const resolvedMeta = isFunction(meta) ? computed(meta) : meta | ||
useNuxtApp()._useHead(resolvedMeta) | ||
} | ||
|
||
// TODO: remove useMeta support when Nuxt 3 is stable | ||
/** @deprecated Please use new `useHead` composable instead */ | ||
export function useMeta (meta: MetaObject | ComputedGetter<MetaObject>) { | ||
export function useMeta (meta: Computable<MetaObject>) { | ||
return useHead(meta) | ||
} |