# @docx-editor\.dev/vue 中文文档

规范地址：https://npmcn.com/package/%40docx-editor.dev/vue/

版本：2\.38\.0
npm 元数据更新时间：2026-11-16T13:51:30.280Z
中文译文更新时间：2026-11-16T13:52:26.786Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40docx-editor.dev/vue
原文对照：https://npmcn.com/package/%40docx-editor.dev/vue/?lang=original
项目主页：https://docx-editor.dev/
源码仓库：https://github.com/eigenpal/docx-editor

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：2 MB，18 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：vue ^3\.3\.0，@docx-editor\.dev/core ~2\.38\.0
- 首次发布：2026-07-16T11:39:51.787Z
- 最新版本发布：2026-11-16T13:51:29.901Z
- 近 30 天下载量：15335（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：56（近 12 个月 56 个）

## 中文简介

Vue 3 DOCX 编辑器适配器,用于@docx-editor.dev编辑合同.

## 安装

```sh
npm install @docx-editor.dev/vue
```

也可以使用：`pnpm add @docx-editor.dev/vue`、`yarn add @docx-editor.dev/vue`、`bun add @docx-editor.dev/vue`

## README

[![DOCX Editor by EigenPal](https://raw.githubusercontent.com/eigenpal/docx-editor/main/.github/assets/readme-logo-light.svg)](https://www.docx-editor.dev/)

# @docx-editor.dev/vue (英语)

使用 Vue 3 组件和可堆肥来打开,编辑并保存 DOCX 文件.

共享引擎处理文档状态,编辑,布局和渲染.

## 特征

-   [打开、编辑并保存文档](https://www.docx-editor.dev/docs/2.x/vue/props)。 。 。 .
-   [编写您的编辑界面](https://www.docx-editor.dev/docs/2.x/vue/composition)。 。 。 .
-   [通过可堆肥连接控制](https://www.docx-editor.dev/docs/2.x/vue/composables)。 。 。 .
-   [翻译编辑器控件](https://www.docx-editor.dev/docs/2.x/i18n)。 。 。 .

## 安装

安装适配器及其所需的引擎端点 :

```bash
npm install @docx-editor.dev/vue @docx-editor.dev/core
```

## 快开始

导入样式表一次, 并给编辑器一个有定义高度的容器 :

```vue
<script setup lang="ts">
import { DocxEditor } from '@docx-editor.dev/vue';
import '@docx-editor.dev/vue/styles.css';
</script>

<template>
  <div style="height: 100vh">
    <DocxEditor document="blank" />
  </div>
</template>
```

要打开文件,请通过文件 `ArrayBuffer` 或者说 `Uint8Array` 作为 `:document`。 。 。 .

## 组成 API

当您需要自己的界面时, 编写编辑器根, 视图和内容 。 在根内设置自定义控制 :

```vue
<script setup lang="ts">
import { DocxEditorRoot, DocxEditorViewport, DocxEditorContent } from '@docx-editor.dev/vue';
import '@docx-editor.dev/vue/styles.css';
import BoldButton from './BoldButton.vue';
</script>

<template>
  <DocxEditorRoot document="blank">
    <BoldButton />
    <DocxEditorViewport style="height: 80vh">
      <DocxEditorContent />
    </DocxEditorViewport>
  </DocxEditorRoot>
</template>
```

定义按钮 `BoldButton.vue`. 作曲体必须运行在以下的后人身上: `DocxEditorRoot` 访问编辑器。 解结构计算校对后, Vue 在模板中解开它们 :

```vue
<script setup lang="ts">
import { useEditorCommand } from '@docx-editor.dev/vue';

const { execute, isEnabled, isActive } = useEditorCommand('text.bold');
</script>

<template>
  <button @mousedown.prevent :disabled="!isEnabled" :aria-pressed="isActive" @click="execute()">
    Bold
  </button>
</template>
```

套件还出口 `useDocxEditor`, (中文(简体) ), `useEditorState`, (中文(简体) ), `useEditorEvent`,以及 `useFontFamily`。 。 。 .

## 安全部门改革和努克特

编辑器需要浏览器 API. 对于Nuxt,把它挂入里面 `<ClientOnly>` 并使用一个 `.client.vue` 进口部分。 对于其它服务器发送的应用程序,导入编辑器并在浏览器中挂载.

Nuxt模块仍然是私人工作空间软件包. 外部应用程序应遵循 [坚果向导](https://www.docx-editor.dev/docs/2.x/frameworks/nuxt)。 。 。 .

## 哪些 API 任务

使用 React 或 Vue 适配器钩, 复检钩,以及 `DocxEditorReview` 从 `@docx-editor.dev/pro/react` 或者说 `@docx-editor.dev/pro/vue` 用于构建浏览器审查控制。 使用编辑 API 在 `@docx-editor.dev/editor-api` 用于文档自动化。 它遵循Office.js对象模型,在浏览器和服务器主机中运行.

| 任务 | 浏览器控制( React 或 Vue) | 文件自动化 |
| --- | --- | --- |
| [对已找到文本的评论](https://www.docx-editor.dev/docs/2.x/recipes/comment-on-found-text) | `editor.findMatches`, (中文(简体) ), `editor.selectMatch`,则 `useReview().comment` | `body.search`,则 `Range.insertComment` |
| [对线索的答复](https://www.docx-editor.dev/docs/2.x/pro/comments) | `useReview().reply(item, text)` | `Comment.reply(text)` |
| [记录跟踪替换](https://www.docx-editor.dev/docs/2.x/recipes/tracked-replacement) | 那么建议模式 `editor.exec({ type: 'replaceMatch', match, text })` | `document.changeTrackingMode = 'TrackMineOnly'`,则 `Range.insertText(text, 'Replace')` |
| [提议将AI重写为已跟踪的更改](https://www.docx-editor.dev/docs/2.x/recipes/propose-rewrite) | `prepareRewrite` 结束 `DocxEditor.createBrowser` | `prepareRewrite` 从 `@docx-editor.dev/editor-api/agent` |
| [接受或拒绝更改](https://www.docx-editor.dev/docs/2.x/recipes/accept-reject-without-scrolling) | `useReview().accept(item)` 或者说 `useReview().reject(item)` | `Revision.accept()` 或者说 `Revision.reject()` |
| [不滚动打开更改](https://www.docx-editor.dev/docs/2.x/recipes/accept-reject-without-scrolling) | `useReview().setActive(key, { reveal: false })` | 不适用:无取景口 |
| [突出显示区域](https://www.docx-editor.dev/docs/2.x/recipes/highlight-ranges) | `useHighlights(name, source, options)` | 不适用 |
| [自定义审查铁路卡](https://www.docx-editor.dev/docs/2.x/recipes/custom-review-cards) | `DocxEditorReview` 与 `preset` 设置为 `false`, (中文(简体) ), `useReviewCardHeights`, (中文(简体) ), `useStackedReviewPositions`,以及 `useReviewRailMetrics` | 不适用 |
| 关于选择的注释按钮 | `DocxEditorReview.AddComment` 作为直系儿童 `DocxEditorReview`,或 `useEditorCommand('review.addComment')` | 不适用 |
| [页面设置和段落对话框](https://www.docx-editor.dev/docs/2.x/customization/dialogs) | `DocxEditor.PageSetupDialog` 或者说 `DocxEditor.ParagraphDialog` | `Section.pageSetup`,以及 `Paragraph` 属性,例如 `alignment` |

这个包装了任务秘方 [`docs/index.md`](https://npmcn.com/package/%40docx-editor.dev/vue/docs/index.md).这些网站还有: [任务配方](https://www.docx-editor.dev/docs/2.x/recipes)。 。 。 .

## 文档和演示

-   [Vue 适配器文件](https://www.docx-editor.dev/docs/2.x/vue)
-   [组成指南](https://www.docx-editor.dev/docs/2.x/vue/composition)
-   [可编目参考](https://www.docx-editor.dev/docs/2.x/vue/composables)
-   [导出 Markdown 和 PDF](https://www.docx-editor.dev/docs/2.x/guides/export)
-   [打印文档](https://www.docx-editor.dev/docs/2.x/guides/print)
-   现场演示 : `bun run dev:vue` 在单体中(`examples/vue`(中文(简体) )

## 许可证

阿帕奇 - 2.0

### 自定义不支持的内容

登记组件 `DocxEditor` 或者说 `DocxEditor.Root`。每个声明处理匹配不支持的内容,包括不透明的内线和块元素.

```vue
<DocxEditor :document="bytes">
  <DocxEditor.UnsupportedElement
    :match="(element) => element.namespaceUri === 'urn:my-widgets'"
    :layout="{ width: 180, height: 48 }"
  >
    <template #default="{ element }">
      <MyWidget :element="element" />
    </template>
  </DocxEditor.UnsupportedElement>
  <DocxEditor.UnsupportedElement>
    <template #default="{ element }">
      <MyPlaceholder :label="element.label" />
    </template>
  </DocxEditor.UnsupportedElement>
</DocxEditor>
```

首个挂载匹配声明取胜. 提案更新保留其优先级. 取消和提出宣言再次给予后来的优先地位。 要暂时禁用特定渲染器, 请保持挂载并更改 `match`,或使用不相重叠的匹配器。 奥米 `match` 为了一个全面。 在上游使用源元数据; 在 pagination 之前没有几何数据 。 返回空位内容以保留默认占位符 。 空结果不选择下一个声明 .

`UnsupportedElement` 曝光情况 `nodeId`, (中文(简体) ), `ownerPartName`, (中文(简体) ), `namespaceUri`, (中文(简体) ), `localName`, (中文(简体) ), `source`, (中文(简体) ), `placement`,以及 `label`。 。 。 . `bounds` 在布局后描述保留框。 可选 `drawing` 财务报告和审定财务报表 `equation` 记录提供专门的元数据。 将源内容视为只读且不可信 .

`layout` 在文档点中保留不透明元素的宽度和高度。 源入会决定内入或块流. 无 `layout`,不透明入内元素预留120×24分;区块预留240×96分. 尺寸必须是正的、有限度的,最多10万分。 绘图和等式回落保留了现有的几何学. 无比不透明的内容保留了它现有的隐形行为. 无支持元素内部的属性、元数据和嵌入式有效载荷不是独立的内容事件.

组成部分保留框架背景和同一页再油漆的当地状态。 当 pagination,虚拟化,或文档更改去除一个发生时,它们可以重挂. 将持久应用数据保存在组件外。 支持更新和声明删除保留文档编辑并取消历史。 自定义渲染不会改变保存的 DOCX 内容 .

## 常见问题

### @docx-editor\.dev/vue 是什么？

Vue 3 DOCX 编辑器适配器,用于@docx-editor\.dev编辑合同\.

### 如何安装 @docx-editor\.dev/vue？

在项目目录运行 npm install @docx-editor\.dev/vue，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@docx-editor\.dev/core（~2\.38\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @docx-editor\.dev/vue 支持 TypeScript 吗？

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

### @docx-editor\.dev/vue 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @docx-editor\.dev/vue 可以商用吗？

@docx-editor\.dev/vue 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @docx-editor\.dev/vue 的下载量有多少？

根据 npm 官方下载统计，@docx-editor\.dev/vue 在 2026/10/13 – 2026/11/11 这 30 天内被下载 15,335 次，日均约 511 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @docx-editor\.dev/vue 还在维护吗？

最新版本 2\.38\.0 发布于 2026/11/16（今天）；至今共发布 56 个版本，其中过去 12 个月发布了 56 个；首次发布于 2026/07/16。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

