# @ant-design-vue/babel-plugin-jsx 中文文档

规范地址：https://npmcn.com/package/%40ant-design-vue/babel-plugin-jsx/

版本：1\.0\.0-rc\.1
npm 元数据更新时间：2023-05-31T01:46:20.467Z
中文译文更新时间：2026-11-06T06:03:07.090Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40ant-design-vue/babel-plugin-jsx
原文对照：https://npmcn.com/package/%40ant-design-vue/babel-plugin-jsx/?lang=original
项目主页：https://github.com/vueComponent/jsx/tree/master/packages/babel-plugin-jsx#readme
源码仓库：https://github.com/vueComponent/jsx

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

- 包体积（解压后）：40.1 kB，10 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：8 个
- 首次发布：2020-05-24T12:58:54.807Z
- 最新版本发布：2020-07-29T04:47:50.920Z
- 近 30 天下载量：9197（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 0 个）

## 中文简介

Vue 3.0 JSX 的 Babel 插件

## 安装

```sh
npm install @ant-design-vue/babel-plugin-jsx
```

也可以使用：`pnpm add @ant-design-vue/babel-plugin-jsx`、`yarn add @ant-design-vue/babel-plugin-jsx`、`bun add @ant-design-vue/babel-plugin-jsx`

## README

# Vue 3.0 的 Babel 插件 JSX

![test](https://github.com/vueComponent/jsx/workflows/test/badge.svg) [![npm package](https://img.shields.io/npm/v/@ant-design-vue/babel-plugin-jsx.svg?style=flat-square)](https://www.npmjs.com/package/@ant-design-vue/babel-plugin-jsx)

加入Vue JSX支持.

页:1 [简体中文](https://npmcn.com/packages/babel-plugin-jsx/README-zh_CN.md)

## 安装

安装插件 :

```bash
npm install @ant-design-vue/babel-plugin-jsx -D
```

然后将插件添加到.babelrc:

```js
{
  "plugins": ["@ant-design-vue/babel-plugin-jsx"]
}
```

## 使用量

### 选项

#### 打开

类型 : `boolean`

默认 : `false`

转换 `on: { click: xx }` 改为 `onClick: xxx`

#### 优化

类型 : `boolean`

默认 : `false`

允许优化与否。 如果你对Vue 3不熟悉,不推荐启用.

#### 海关元素

类型 : `(tag: string) => boolean`

默认 : `undefined`

配置自定义元素

## 语法

### 内容

职能构成部分

```jsx
const App = () => <div></div>;
```

已生效

```jsx
const App = {
  render() {
    return <div>Vue 3.0</div>;
  }
};
```

```jsx
const App = defineComponent(() => {
  const count = ref(0);

  const inc = () => {
    count.value++;
  };

  return () => (
    <div onClick={inc}>
      {count.value}
    </div>
  );
});
```

```jsx
import { withModifiers } from 'vue';

const App = () => {
  const count = ref(0);

  const inc = () => {
    count.value++;
  };

  return () => (
    <div onClick={withModifiers(inc, ['self'])}>
      {count.value}
    </div>
  );
}
```

断裂

```jsx
const App = () => (
  <>
    <span>I'm</span>
    <span>Fragment</span>
  </>
);
```

### 属性/ 道具

```jsx
const App = () => <input type="email" />;
```

带有动态绑定的:

```jsx
const placeholderText = 'email';
const App = () => (
  <input
    type="email"
    placeholder={placeholderText}
  />
);
```

### 指令

v 显示

```jsx
const App = {
  data() {
    return { visible: true };
  },
  render() {
    return <input v-show={this.visible} />;
  },
};
```

v 型号

> 注意: 您应该通过第二个参数作为字符串来使用 `arg`。 。 。 .

```jsx
<input v-model={val} />
```

```jsx
<input v-model={[val, ['trim']]} />
```

```jsx
<A v-model={[val, 'foo', ['bar']]} />
```

将汇编到:

```js
h(A, {
  'foo': val,
  "fooModifiers": {
    "bar": true
  },
  "onUpdate:foo": $event => val = $event
})
```

自定义指令

```jsx
const App = {
  directives: { custom: customDirective },
  setup() {
    return () => (
      <a
        v-custom={[val, 'arg', ['a', 'b']]}
      />
    );
  },
};
```

### 槽

```jsx
const App = {
  setup() {
    const slots = {
      default: () => <div>A</div>,
      foo: () => <span>B</span>
    };
    return () => <A v-slots={slots} />;
  }
};
```

## 谁在用

<table><tbody><tr><td align="center"><a href="https://www.antdv.com/" rel="nofollow noopener noreferrer"><img src="https://qn.antdv.com/logo.png" width="32" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><strong>蚂蚁设计Vue</strong></a></td><td align="center"><a href="https://youzan.github.io/vant/#/zh-CN/" rel="nofollow noopener noreferrer"><img src="https://img.yzcdn.cn/vant/logo.png" width="32" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><strong>范特语</strong></a></td></tr></tbody></table>

## 兼容性

此 repo 仅兼容 :

-   **贝贝 7+**
-   **第3号+**

## 常见问题

### @ant-design-vue/babel-plugin-jsx 是什么？

Vue 3\.0 JSX 的 Babel 插件

### 如何安装 @ant-design-vue/babel-plugin-jsx？

在项目目录运行 npm install @ant-design-vue/babel-plugin-jsx，或使用 pnpm add / yarn add / bun add。

### @ant-design-vue/babel-plugin-jsx 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/ant-design-vue\_\_babel-plugin-jsx 是否存在。

### @ant-design-vue/babel-plugin-jsx 支持 ESM 还是 CommonJS？

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

### @ant-design-vue/babel-plugin-jsx 可以商用吗？

@ant-design-vue/babel-plugin-jsx 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ant-design-vue/babel-plugin-jsx 的下载量有多少？

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

### @ant-design-vue/babel-plugin-jsx 还在维护吗？

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

