@desource/context7-widget-nuxt

中文文档
0.2.3发布于 2026/11/01MITTypeScriptES Module构建来源已验证近 30 天下载 1.7万

Nuxt 3 and Nuxt 4 module for the native Vue Context7 documentation chat widget.

原始使用文档
文档目录14 节
  1. Why Use This Widget?
  2. Before You Start
  3. Install
  4. Examples
  5. Render the widget
  6. Control open state
  7. Use the composable
  8. Use a custom trigger
  9. Module options
  10. Customization
  11. TypeScript
  12. SSR behavior
  13. Data flow and privacy
  14. Related packages

@desource/context7-widget-nuxt

Nuxt Coverage SonarCloud Ask Context7 Ask DeepWiki License

Add Context7 docs chat to Nuxt 3 or 4 and style it to match your site. This MIT-licensed module sets up the native Vue widget, its stylesheet, auto-imports, and app-wide defaults.

Why Use This Widget?

Context7 provides its docs widget and hosted AI answers for free. Its basic styling can leave chat looking out of place. This upgrade adds fonts, colors, custom triggers, and layouts to match your site, plus copyable code, multiline input, Stop, and Retry.

Upgrade your existing script or add the module below with the same library and domain settings. New to Context7? Help visitors explore your library and start their first integration. The module reuses Vue and the shared core.

Before You Start

Use a library you have claimed on Context7. In its Admin → Chat settings, enable the widget, add your site's domain to the allowed domains, and save. Replace /owner/repo in the examples with that library's id. A library being indexed alone does not enable chat on your site. See Context7's widget setup.

Install

pnpm add @desource/context7-widget-nuxt

Add the module and configure the documentation library once:

export default defineNuxtConfig({
  modules: ['@desource/context7-widget-nuxt'],
  context7Widget: {
    defaults: {
      library: '/owner/repo'
    }
  }
});

Context7Widget and useContext7Widget are now available without imports. The stylesheet is added before application CSS so application rules can override it.

Examples

Render the widget

<template>
  <Context7Widget />
</template>

Props override module defaults for that instance:

<template>
  <Context7Widget
    library="/owner/another-repo"
    position="anchor"
    preset="glass"
    theme="auto"
    widget-id="nuxt-docs"
    @question="onQuestion"
  />
</template>

<script setup lang="ts">
import type { Context7WidgetQuestionEventDetail } from '@desource/context7-widget-vue';

function onQuestion(detail: Context7WidgetQuestionEventDetail) {
  console.log(detail.library, detail.question);
}
</script>

Control open state

<script setup lang="ts">
const open = ref(false);
</script>

<template>
  <button type="button" @click="open = true">Ask documentation</button>
  <Context7Widget v-model:open="open" position="center" />
</template>

Use the composable

useContext7Widget can control a rendered widget by widgetId or mount a native Vue widget programmatically after the owner component mounts.

<script setup lang="ts">
const docs = useContext7Widget({ widgetId: 'docs' });

async function ask() {
  docs.open();
  await docs.send('How do I configure this module?');
}
</script>

<template>
  <button type="button" @click="ask">Ask</button>
  <Context7Widget widget-id="docs" />
</template>

For programmatic mounting:

<script setup lang="ts">
const docs = useContext7Widget({
  autoMount: true,
  library: '/owner/repo',
  preset: 'terminal',
  widgetId: 'programmatic-docs'
});
</script>

<template>
  <button type="button" @click="docs.toggle">Toggle documentation chat</button>
</template>

Use a custom trigger

<template>
  <Context7Widget custom-trigger launcher-label="Ask docs">
    <template #trigger="{ label }">
      <span>{{ label }}</span>
    </template>
  </Context7Widget>
</template>

External selector, Vue ref, and direct Element triggers work as described by the Vue package.

Module options

export default defineNuxtConfig({
  modules: ['@desource/context7-widget-nuxt'],
  context7Widget: {
    component: true,
    componentName: 'Context7Widget',
    composable: true,
    css: true,
    defaults: {
      library: '/owner/repo',
      preset: 'default',
      theme: 'auto'
    }
  }
});
OptionDefaultPurpose
componenttrueAuto-register the native Vue component
componentNameContext7WidgetChange the auto-imported component name
composabletrueAuto-import useContext7Widget
csstrueAdd @desource/context7-widget-vue/styles.css globally
defaults{}Provide app-wide widget props to components and composables

defaults accepts serializable widget props. Instance props take precedence. Controlled open state and DOM-backed customTrigger values belong on a component instance, so the module type excludes them.

Disable unused integrations when an application imports them another way:

export default defineNuxtConfig({
  modules: ['@desource/context7-widget-nuxt'],
  context7Widget: {
    component: false,
    composable: false,
    css: false
  }
});

The component and composable are registered as Nuxt auto-imports. Nuxt only includes them in an application chunk when used.

Customization

Module defaults set the common theme, placement, dimensions, labels, and library:

export default defineNuxtConfig({
  modules: ['@desource/context7-widget-nuxt'],
  context7Widget: {
    defaults: {
      color: '#7cffb2',
      labels: {
        send: 'Ask'
      },
      panelHeight: 'min(42rem, 80vh)',
      panelWidth: 'min(28rem, calc(100vw - 2rem))',
      position: 'bottom-right',
      preset: 'glass',
      title: 'Project documentation'
    }
  }
});

Override CSS variables and public parts from application CSS:

.context7-widget[widget-id='docs'] {
  --c7-accent: #7cffb2;
  --c7-panel-background: #101513;
  --c7-panel-color: #f7f2e8;
  --c7-panel-radius: 8px;
}

.context7-widget [part~='send-button'] {
  min-width: 5rem;
}

Set css: false if the application imports @desource/context7-widget-vue/styles.css itself.

TypeScript

Module options are typed through Nuxt's context7Widget config key. Import component, event, option, controller, and composable types from @desource/context7-widget-vue:

import type {
  Context7WidgetController,
  Context7WidgetProps,
  Context7WidgetQuestionEventDetail,
  UseContext7WidgetReturn
} from '@desource/context7-widget-vue';

The module does not duplicate the Vue package's type export list as global auto-imports. New Vue types remain available without Nuxt module changes.

SSR behavior

The native Vue component is SSR-safe and does not need ClientOnly. Browser-only behavior starts after mount. useContext7Widget can be created during setup on the server; its imperative mount() method requires a browser document.

Data flow and privacy

The browser posts the configured library id and current conversation directly to https://context7.com/api/v2/widget/chat. The module adds no proxy, analytics, cookies, or persistent storage. Event handlers in the host application can expose question and answer data to any logging or analytics system they call.

版本与发布记录

@desource/context7-widget-nuxt 共发布 5 个版本,首次发布于 2026/09/10;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.3latest2026/11/0111 天前
0.2.22026/10/101 个月前
0.2.12026/10/011 个月前
0.2.02026/09/141 个月前
0.1.02026/09/102 个月前

关于 @desource/context7-widget-nuxt 的常见问题

@desource/context7-widget-nuxt 是什么?

Nuxt 3 and Nuxt 4 module for the native Vue Context7 documentation chat widget.

如何安装 @desource/context7-widget-nuxt?

在项目目录运行 npm install @desource/context7-widget-nuxt,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.5.0)、nuxt(^3.17.0 || ^4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@desource/context7-widget-nuxt 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@desource/context7-widget-nuxt 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@desource/context7-widget-nuxt 可以商用吗?

@desource/context7-widget-nuxt 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@desource/context7-widget-nuxt 的下载量有多少?

根据 npm 官方下载统计,@desource/context7-widget-nuxt 在 2026/10/12 – 2026/11/10 这 30 天内被下载 16,979 次,日均约 566 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@desource/context7-widget-nuxt 还在维护吗?

最新版本 0.2.3 发布于 2026/11/01(11 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/09/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。