# Babel Plugin JSX for Vue 3.0 [![CircleCI](https://circleci.com/gh/vuejs/jsx-next.svg?style=svg)](https://circleci.com/gh/vuejs/vue-next) [![npm package](https://img.shields.io/npm/v/@vue/babel-plugin-jsx.svg?style=flat-square)](https://www.npmjs.com/package/@vue/babel-plugin-jsx) To add Vue JSX support. English | [简体中文](/packages/babel-plugin-jsx/README-zh_CN.md) ## Installation Install the plugin with: ```bash npm install @vue/babel-plugin-jsx -D ``` Then add the plugin to .babelrc: ```js { "plugins": ["@vue/babel-plugin-jsx"] } ``` ## Usage ### options #### transformOn Type: `boolean` Default: `false` transform `on: { click: xx }` to `onClick: xxx` #### optimize Type: `boolean` Default: `false` enable optimization or not. It's not recommended to enable it If you are not familiar with Vue 3. #### isCustomElement Type: `(tag: string) => boolean` Default: `undefined` configuring custom elements ## Syntax ### Content functional component ```jsx const App = () =>
Vue 3.0
; ``` with render ```jsx const App = { render() { return
Vue 3.0
; } }; ``` ```jsx import { withModifiers, defineComponent } from 'vue'; const App = defineComponent({ setup() { const count = ref(0); const inc = () => { count.value++; }; return () => (
{count.value}
); } }) ``` Fragment ```jsx const App = () => ( <> I'm Fragment ); ``` ### Attributes / Props ```jsx const App = () => ; ``` with a dynamic binding: ```jsx const placeholderText = 'email'; const App = () => ( ); ``` ### Directives v-show ```jsx const App = { data() { return { visible: true }; }, render() { return ; }, }; ``` v-model > Note: You should pass the second param as string for using `arg`. ```jsx ``` ```jsx ``` ```jsx ``` Will compile to: ```js h(A, { 'foo': val, "fooModifiers": { "bar": true }, "onUpdate:foo": $event => val = $event }) ``` custom directive ```jsx const App = { directives: { custom: customDirective }, setup() { return () => ( ); }, }; ``` ### Slot ```jsx const App = { setup() { const slots = { default: () =>
A
, foo: () => B }; return () =>
; } }; ``` ### In TypeScript `tsconfig.json`: ```json { "compilerOptions": { "jsx": "preserve" } } ``` ## Who is using

Ant Design Vue

Vant
## Compatibility This repo is only compatible with: - **Babel 7+** - **Vue 3+**