2021-07-15 11:28:04 +00:00
|
|
|
import { isFunction } from '@vue/shared'
|
2021-12-14 13:29:57 +00:00
|
|
|
import { computed } from 'vue'
|
2021-08-09 16:18:21 +00:00
|
|
|
import type { ComputedGetter } from '@vue/reactivity'
|
2021-11-23 10:16:11 +00:00
|
|
|
import type { MetaObject } from '@nuxt/schema'
|
2021-08-27 13:30:53 +00:00
|
|
|
import { useNuxtApp } from '#app'
|
2021-07-15 11:28:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-04-05 14:02:29 +00:00
|
|
|
export function useHead (meta: MetaObject | ComputedGetter<MetaObject>) {
|
2021-07-28 11:48:17 +00:00
|
|
|
const resolvedMeta = isFunction(meta) ? computed(meta) : meta
|
2022-04-05 14:02:29 +00:00
|
|
|
useNuxtApp()._useHead(resolvedMeta)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove useMeta support when Nuxt 3 is stable
|
2022-04-09 09:46:29 +00:00
|
|
|
/** @deprecated Please use new `useHead` composable instead */
|
2022-04-05 14:02:29 +00:00
|
|
|
export function useMeta (meta: MetaObject | ComputedGetter<MetaObject>) {
|
|
|
|
return useHead(meta)
|
2021-07-15 11:28:04 +00:00
|
|
|
}
|