a54a6a6d1da2c368e8475bab376fa60d4d194b56bd899be20ff2477041e42c2bfdcd943172da8b44827dd8091471a461d0a7cb0f9ba3de0e5682977356ff47 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. ```