布局
Nuxt Kit 提供了一组实用程序来帮助你使用布局。
布局用于封装你的页面。它可以用来封装页面,其中包含常用组件,例如页眉和页脚。可以使用 addLayout
实用程序注册布局。
¥Layouts is used to be a wrapper around your pages. It can be used to wrap your pages with common components, for example, a header and a footer. Layouts can be registered using addLayout
utility.
addLayout
将模板注册为布局并将其添加到布局中。
¥Register template as layout and add it to the layouts.
类型
¥Type
function addLayout (layout: NuxtTemplate | string, name: string): void
interface NuxtTemplate {
src?: string
filename?: string
dst?: string
options?: Record<string, any>
getContents?: (data: Record<string, any>) => string | Promise<string>
write?: boolean
}
参数
¥Parameters
layout
类型:NuxtTemplate | string
¥Type: NuxtTemplate | string
必需:true
¥Required: true
模板对象或包含模板路径的字符串。如果提供了字符串,它将被转换为模板对象,并将 src
设置为该字符串值。如果提供了模板对象,它必须具有以下属性:
¥A template object or a string with the path to the template. If a string is provided, it will be converted to a template object with src
set to the string value. If a template object is provided, it must have the following properties:
src
(可选)
类型:string
模板的路径。如果未提供src
,则必须提供getContents
。filename
(可选)
类型:string
模板文件名。如果未提供filename
,则它将从src
路径生成。在这种情况下,src
选项是必需的。dst
(可选)
类型:string
目标文件的路径。如果未提供dst
,则它将从filename
路径和 nuxtbuildDir
选项生成。options
(可选)
类型:Options
传递给模板的选项。getContents
(可选)
类型:(data: Options) => string | Promise<string>
一个函数,用于使用options
对象调用。它应该返回一个字符串或一个解析为字符串的 Promise。如果提供了src
,则此函数将被忽略。write
(可选)
类型:boolean
如果设置为true
,模板将被写入目标文件。否则,该模板将仅在虚拟文件系统中使用。