Nuxt 套件
Nuxt Kit 提供可组合实用程序,使与 Nuxt 钩子、Nuxt 接口 的交互以及开发 Nuxt 模块 变得非常容易。
¥Nuxt Kit provides composable utilities to make interacting with Nuxt Hooks, the Nuxt Interface and developing Nuxt Modules super easy.
:
探索所有 Nuxt Kit 实用程序。
¥Discover all Nuxt Kit utilities.
::
用法
¥Usage
安装依赖
¥Install Dependency
你可以通过将最新的 Nuxt Kit 添加到 package.json
的 dependencies
部分来安装它。但是,即使 Nuxt 已经安装了 @nuxt/kit
包,也请始终考虑显式安装它。
¥You can install the latest Nuxt Kit by adding it to the dependencies
section of your package.json
. However, please consider always explicitly installing the @nuxt/kit
package even if it is already installed by Nuxt.
@nuxt/kit
和 @nuxt/schema
是 Nuxt 的关键依赖。如果你要单独安装,请确保 @nuxt/kit
和 @nuxt/schema
的版本等于或高于你的 nuxt
版本,以避免任何意外行为。{
"dependencies": {
"@nuxt/kit": "npm:@nuxt/kit-nightly@latest"
}
}
导入 Kit 工具
¥Import Kit Utilities
import { useNuxt } from '@nuxt/kit'
Nuxt Kit 是 仅限 esm 的软件包 的子集,这意味着你不能使用 require('@nuxt/kit')
。作为一种解决方法,请在 CommonJS 上下文中使用动态导入:
¥Nuxt Kit is an esm-only package meaning that you cannot require('@nuxt/kit')
. As a workaround, use dynamic import in the CommonJS context:
// This does NOT work!
// const kit = require('@nuxt/kit')
async function main() {
const kit = await import('@nuxt/kit')
}
main()