Overview
The Babel preset babel-preset-vca-jsx provides support for automatic import of createElement as h, setup functional component syntax, and setup template refs. This preset is useful for projects using the @vue/composition-api and @vue/cli-plugin-babel packages.
Features
- Automatic import of
createElementash: Allows for importingcreateElementashwhen writing JSX. - Functional component syntax of the setup(): Supports the functional component syntax of the
setup()function by default. - Allocating template refs with JSX on the render function returned by setup(): Enables the allocation of template refs with JSX on the render function returned by
setup(). - Fixed @vue/babel-sugar-v-model@1.1.2 calling
thisin setup(): Fixes an issue with callingthisin thesetup()function when using@vue/babel-sugar-v-model@1.1.2.
Installation
To use babel-preset-vca-jsx, follow these steps:
Install the
@vue/composition-apiand@vue/cli-plugin-babelpackages in your project.Configure your
babel.config.jsfile to include the preset:module.exports = { presets: [ 'babel-preset-vca-jsx' ] };Note that there is a distinction between the default functional component and the composition-api-based functional component in this preset.
For the default functional component, which essentially translates to the render function, the JSX shorthand is as follows:
- The first letter of the variable name must be capitalized.
- For details of the callback parameters, refer to the specific details.
For the composition-api-based functional component, which essentially translates to the
setup()function, the JSX shorthand is as follows:- The difference from the default functional component is that a render function is returned.
Summary
The babel-preset-vca-jsx preset provides support for automatic import of createElement as h, functional component syntax of setup(), and allocation of template refs with JSX. By using this preset and following the installation guide, developers can enhance their projects using the @vue/composition-api and @vue/cli-plugin-babel packages.