useHead
useHead 可自定义 Nuxt 应用各个页面的 head 属性。
useHead 可组合函数允许你以编程式和响应式的方式管理 head 标签,这得益于 Unhead 的支持。如果数据来自用户或其他不受信任的来源,我们建议你查看 useHeadSafe。
¥The useHead composable function allows you to manage your head tags in a programmatic and reactive way, powered by Unhead. If the data comes from a user or other untrusted source, we recommend you check out useHeadSafe.
类型
¥Type
useHead(meta: MaybeComputedRef<MetaObject>): void
以下是 useHead 的非反应式类型。
¥Below are the non-reactive types for useHead .
interface MetaObject {
title?: string
titleTemplate?: string | ((title?: string) => string)
base?: Base
link?: Link[]
meta?: Meta[]
style?: Style[]
script?: Script[]
noscript?: Noscript[]
htmlAttrs?: HtmlAttributes
bodyAttrs?: BodyAttributes
}
有关更详细的类型,请参阅 @unhead/vue。
¥See @unhead/vue for more detailed types.
useHead 的属性可以是动态的,接受 ref、computed 和 reactive 属性。meta 参数还可以接受返回对象的函数,以使整个对象具有响应性。参数
¥Params
meta
类型:MetaObject
¥Type: MetaObject
接受以下头部元数据的对象:
¥An object accepting the following head metadata:
meta:数组中的每个元素都映射到一个新创建的<meta>标签,其中对象属性映射到相应的属性。- 类型:
Array<Record<string, any>>
- 类型:
link:数组中的每个元素都映射到一个新创建的<link>标签,其中对象属性映射到相应的属性。- 类型:
Array<Record<string, any>>
- 类型:
style:数组中的每个元素都映射到一个新创建的<style>标签,其中对象属性映射到相应的属性。- 类型:
Array<Record<string, any>>
- 类型:
script:数组中的每个元素都映射到一个新创建的<script>标签,其中对象属性映射到相应的属性。- 类型:
Array<Record<string, any>>
- 类型:
noscript:数组中的每个元素都映射到一个新创建的<noscript>标签,其中对象属性映射到相应的属性。- 类型:
Array<Record<string, any>>
- 类型:
titleTemplate:配置动态模板以自定义单个页面的页面标题。- 类型:
string|((title: string) => string)
- 类型:
title:在单个页面上设置静态页面标题。- 类型:
string
- 类型:
bodyAttrs:设置<body>标签的属性。每个对象属性都映射到相应的属性。- 类型:
Record<string, any>
- 类型:
htmlAttrs:设置<html>标签的属性。每个对象属性都映射到相应的属性。- 类型:
Record<string, any>
- 类型: