# @api-components/api-body-editor 中文文档

规范地址：https://npmcn.com/package/%40api-components/api-body-editor/

版本：4\.0\.10
npm 元数据更新时间：2026-04-07T19:23:34.554Z
中文译文更新时间：2026-11-06T12:49:47.316Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40api-components/api-body-editor
原文对照：https://npmcn.com/package/%40api-components/api-body-editor/?lang=original
项目主页：https://github.com/advanced-rest-client/api-body-editor#readme
源码仓库：https://github.com/advanced-rest-client/api-body-editor

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

- 包体积（解压后）：51.7 kB，9 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：18 个
- 首次发布：2018-05-21T23:13:20.848Z
- 最新版本发布：2022-09-21T14:46:48.497Z
- 近 30 天下载量：3191（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 0 个）

## 中文简介

渲染不同种类的人体编辑器. 它与AMF数据模型合作

## 安装

```sh
npm install @api-components/api-body-editor
```

也可以使用：`pnpm add @api-components/api-body-editor`、`yarn add @api-components/api-body-editor`、`bun add @api-components/api-body-editor`

## README

# 被否决

这一构成部分已贬值。 代码基础已移动到 [api 请求](https://github.com/advanced-rest-client/api-request) 模块.

* * *

对应所选媒体类型的Renders正体编辑器.

它与AMF数据模型合作,以产生有值的预先被流行的视图.

**参见此文档下方的断开更改和所需依赖性列表**

## 版本兼容性

此版本仅与AMF模式版本2(AMF parser QQ 4.0.0)相通. 用于与上一个模型版本的兼容性 `3.x.x` 版本的组件.

## 使用量

### 安装

```
npm install --save @api-components/api-body-editor
```

### 在 html 文件内

```html
<html>
  <head>
    <script type="module">
      import '@api-components/api-body-editor/api-body-editor.js';
    </script>
  </head>
  <body>
    <api-body-editor></api-body-editor>
    <script>
    {
      document.querySelector('api-body-editor').addEventListener('value-changed', (e) => {
        console.log(e.detail.value);
      });
    }
    </script>
  </body>
</html>
```

### 在一个LitElement中

```js
import { LitElement, html } from 'lit-element';
import '@api-components/api-body-editor/api-body-editor.js';

class SampleElement extends PolymerElement {
  render() {
    return html`
    <api-body-editor
      allowdisableparams
      allowcustom
      allowhideoptional
      .contentType="${this.contentType}"
      @value-changed="${this._handleValue}"></api-headers-editor>
    `;
  }

  _handleValue(e) {
    this.bodyValue = e.target.value;
  }
}
customElements.define('sample-element', SampleElement);
```

## 发展

### 本地运行演示

```sh
npm start
```

### 运行测试

```sh
npm test
```

### API 组件

此组件是 [API 生态系统组成部分](https://elements.advancedrestclient.com/)

## V3 中突破更改

在导入此元素前, 您需要将 CodeMiror 包含在文档中 因为它期望这个全球变量已经设定.

这是CodeMiror无法作为ES模块运行的原因.

使用您的构建系统将 CodeMiror 捆绑到构建中, 不要忘记输出全局变量 .

```html
<!-- CodeMirror + modes loader -->
<script src="node_modules/codemirror/lib/codemirror.js"></script>
<script src="node_modules/codemirror/addon/mode/loadmode.js"></script>
<script src="node_modules/codemirror/mode/meta.js"></script>
<!--Default set of parsers, add as many as you need -->
<script src="node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="node_modules/codemirror/mode/xml/xml.js"></script>
<script src="node_modules/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<!-- JSON linter -->
<script src="node_modules/jsonlint/lib/jsonlint.js"></script>
<script src="node_modules/codemirror/addon/lint/lint.js"></script>
<script src="node_modules/codemirror/addon/lint/json-lint.js"></script>
```

添加 linter 弹出样式 :

```html
<link rel="stylesheet" href="node_modules/codemirror/addon/lint/lint.css" />
```

最后,您应该设置 CodeMiror 模式的路径 。 当内容类型改变 此路径用于装入语法亮点 。 如果您在脚本中列出所有模式 以上则不需要.

```html
<script>
CodeMirror.modeURL = 'node_modules/codemirror/mode/%N/%N.js';
</script>
```

这个 `jsonlint` 库是 `@api-components/code-mirror-linter` 已包含在此元素的依赖图中.

## 常见问题

### @api-components/api-body-editor 是什么？

渲染不同种类的人体编辑器\. 它与AMF数据模型合作

### 如何安装 @api-components/api-body-editor？

在项目目录运行 npm install @api-components/api-body-editor，或使用 pnpm add / yarn add / bun add。

### @api-components/api-body-editor 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/api-components\_\_api-body-editor 是否存在。

### @api-components/api-body-editor 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @api-components/api-body-editor 可以商用吗？

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

### @api-components/api-body-editor 的下载量有多少？

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

### @api-components/api-body-editor 还在维护吗？

最新版本 4\.0\.10 发布于 2022/09/21（4 年前）；至今共发布 20 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/05/22。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

