4a3d88a9b1a736506a7684f9c2158f2645d0d6f090018e286888e88efe086d8941838618defc5906173b7ad608eb274e59f23a3bc6378a973551d399330d86 1.1 KB

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