From cc182454776a2e29b0320e4f9693758ace0f4ad9 Mon Sep 17 00:00:00 2001 From: Krutie Patel Date: Wed, 31 Aug 2022 00:20:47 +1000 Subject: [PATCH 1/8] docs(api): enhance useHead composable --- docs/content/3.api/1.composables/use-head.md | 138 ++++++++++++++++--- 1 file changed, 117 insertions(+), 21 deletions(-) diff --git a/docs/content/3.api/1.composables/use-head.md b/docs/content/3.api/1.composables/use-head.md index 411e50a7dff..60f5e467811 100644 --- a/docs/content/3.api/1.composables/use-head.md +++ b/docs/content/3.api/1.composables/use-head.md @@ -1,48 +1,144 @@ # `useHead` -::ReadMore{link="/guide/features/head-management"} +Nuxt provides `useHead` composable to add and customize the head properties of individual pages of Nuxt app. Unlike [definePageMeta](/api/utils/define-page-meta), properties of `useHead` can be dynamic and can accept a function returning the object with reactive metadata. -Nuxt provides a composable to update the head properties of your page with an [`MetaObject`](/api/composables/use-head/#metaobject) of meta properties with keys corresponding to meta tags: +`useHead` accepts properties of type `MetaObject` as listed below. -`title`, `base`, `script`, `noscript`, `style`, `meta` and `link`, as well as `htmlAttrs` and `bodyAttrs`. Alternatively, you can pass a function returning the object for reactive metadata. +## Type -```js +```js [Signature] useHead(options: MetaObject) + +interface MetaObject extends Record { + charset?: string + viewport?: string + meta?: Array> + link?: Array> + style?: Array> + script?: Array> + noscript?: Array> + titleTemplate?: string | ((title: string) => string) + title?: string + bodyAttrs?: Record + htmlAttrs?: Record +} ``` +Application-wide configuration of the same properties listed above is possible through [nuxt.config](/api/configuration/nuxt.config#head). However, `useHead` composable allows customizing these properties at page-level. + ::alert{icon=👉} **`useHead` only works during `setup`**. :: -## Example +## Properties + +* **charset**: `type: string` | `default: 'utf-8'` - Character encoding in which the document is encoded + +* **viewport**: `type: string` | `default: 'width=device-width, initial-scale=1'` - Configure the viewport (the area of the window in which web content can be seen) + +* **meta**: `type: array` - Each item in meta array maps to a newly-created `` element, where object properties map to attributes. + +* **link**: `type: array` - Each item maps to a newly-created `` element, where object properties map to attributes. + +* **style**: `type: array` - Each item maps to a newly-created `