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.

48 lines
1009 B

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