Nuxt 套件

@nuxt/kit provides features for module authors.

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.

:

Read more in Docs > API > Kit.

探索所有 Nuxt Kit 实用程序。

¥Discover all Nuxt Kit utilities.

::

用法

¥Usage

安装依赖

¥Install Dependency

你可以通过将最新的 Nuxt Kit 添加到 package.jsondependencies 部分来安装它。但是,即使 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 版本,以避免任何意外行为。
package.json
{
  "dependencies": {
    "@nuxt/kit": "npm:@nuxt/kit-nightly@latest"
  }
}

导入 Kit 工具

¥Import Kit Utilities

test.mjs
import { useNuxt } from '@nuxt/kit'
Read more in Docs > API > Kit.
Nuxt Kit 实用程序仅适用于模块,不能在运行时导入(组件、Vue 可组合项、页面、插件或服务器路由)。

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:

test.cjs
// This does NOT work!
// const kit = require('@nuxt/kit')
async function main() {
  const kit = await import('@nuxt/kit')
}
main()