You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

1 month ago
  1. ## @vue/babel-sugar-composition-api-inject-h
  2. > Ported from [luwanquan/babel-preset-vca-jsx](https://github.com/luwanquan/babel-preset-vca-jsx) by [@luwanquan](https://github.com/luwanquan)
  3. Syntactic sugar for automatic `h` inject in JSX with @vue/composition-api.
  4. ### Babel Compatibility Notes
  5. - This repo is only compatible with Babel 7.x
  6. ### Usage
  7. Install the dependencies:
  8. ```sh
  9. # for yarn:
  10. yarn add @vue/babel-sugar-composition-api-inject-h
  11. # for npm:
  12. npm install @vue/babel-sugar-composition-api-inject-h --save
  13. ```
  14. In your `.babelrc`:
  15. ```json
  16. {
  17. "plugins": ["@vue/babel-sugar-composition-api-inject-h"]
  18. }
  19. ```
  20. However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead.
  21. ### Details
  22. This plugin automatically injects `h` in every method that has JSX. By using this plugin you don't have to always import `h` from `@vue/composition-api`.
  23. ```js
  24. // Without @vue/babel-sugar-inject-h
  25. import { h } from '@vue/composition-api'
  26. export default {
  27. setup() {
  28. return () => <button />
  29. },
  30. }
  31. ```
  32. ```js
  33. // With @vue/babel-sugar-inject-h
  34. export default {
  35. setup() {
  36. return () => <button />
  37. },
  38. }
  39. ```