mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-13 02:59:13 +08:00
9c464f4ce5
* chore: lockfile should be committed to the repo See https://classic.yarnpkg.com/blog/2016/11/24/lockfiles-for-all/ * chore: explicitly set the npm client to yarn * chore: set up yarn workspaces * chore: use jest.config.js See: https://jestjs.io/docs/en/configuration Better follow the convention than to define yet another config file name * test: the `globals` configuration is redundant * chore: prefer babel.config.js over .babelrc See https://babeljs.io/docs/en/config-files * chore: the jsxInjection alias is extraneous * chore: add .js extension to eslint config It is the preferred configuration file format. https://eslint.org/docs/user-guide/configuring#configuration-file-formats Also deleted the jasmine env as it's not used in this project. * chore: downgrade to eslint v6 for compatibility with other dependencies * chore: use eslint-config-airbnb-base instead of the full airbnb config * chore: remove babel-eslint Syntax used in this repo can already be parsed with the default ESLint parser * chore: add missing peer dependency for `@vue/test-utils` * chore: enable useWorkspaces in lerna |
||
---|---|---|
.. | ||
example | ||
src | ||
test | ||
babel.config.js | ||
index.html | ||
jest.config.js | ||
package.json | ||
README.md | ||
webpack.config.js |
@ant-design-vue/babel-plugin-jsx
To add Vue JSX support.
Installation
Install the plugin with:
npm install @ant-design-vue/babel-plugin-jsx
Then add the plugin to .babelrc:
{
"plugins": ["@ant-design-vue/babel-plugin-jsx"]
}
Syntax
Content
functional component
const App = () => <div></div>
with render
const App = {
render() {
return <div>Vue 3.0</div>
}
}
const App = defineComponent(() => {
const count = ref(0);
const inc = () => {
count.value++;
};
return () => (
<div onClick={inc}>
{count.value}
</div>
)
})
fragment
const App = () => (
<>
<span>I'm</span>
<span>Fragment</span>
</>
)
Attributes/Props
const App = () => <input type="email" />
with a dynamic binding:
const placeholderText = 'email'
const App = () => (
<input
type="email"
placeholder={placeholderText}
/>
)
Directives
It is recommended to use camelCase version of it (
vModel
) in JSX, but you can use kebab-case too (v-model
).
v-show
const App = {
data() {
return { visible: true };
},
render() {
return <input vShow={this.visible} />;
},
};
v-model
- You should use underscore (
_
) instead of dot (.
) for modifiers (vModel_trim={this.test}
)
export default {
data: () => ({
test: 'Hello World',
}),
render() {
return (
<>
<input type="text" vModel_trim={this.test} />
{this.test}
</>
)
},
}