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.

52 lines
1.1 KiB

1 month ago
  1. ## @vue/babel-sugar-v-on
  2. Syntactic sugar for v-on 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-v-on
  10. # for npm:
  11. npm install @vue/babel-sugar-v-on --save
  12. ```
  13. In your `.babelrc`:
  14. ```json
  15. {
  16. "plugins": ["@vue/babel-sugar-v-on"]
  17. }
  18. ```
  19. However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead.
  20. ### Details
  21. This plugin adds v-on to the JSX and tries to mirror the same behaviour as in vue-template-compiler, with a few differences:
  22. 1. You should use underscore (`_`) instead of dot (`.`) for modifiers (`vOn:click_prevent={this.test}`)
  23. 2. It is recommended to use camelCase version of it (`vOn`) in JSX, but you can use kebab-case too (`v-on`).
  24. ```js
  25. export default {
  26. methods: {
  27. test() {
  28. console.log('Hello World')
  29. },
  30. },
  31. render(h) {
  32. return (
  33. <div>
  34. <a href="https://vuejs.org" vOn:click={this.test}>Vue</a>
  35. </div>
  36. )
  37. },
  38. }
  39. ```