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.

51 lines
1.1 KiB

1 month ago
  1. ## @vue/babel-sugar-v-model
  2. Syntactic sugar for v-model 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-model
  10. # for npm:
  11. npm install @vue/babel-sugar-v-model --save
  12. ```
  13. In your `.babelrc`:
  14. ```json
  15. {
  16. "plugins": ["@vue/babel-sugar-v-model"]
  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-model 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 (`vModel_trim={this.test}`)
  23. 2. It is recommended to use camelCase version of it (`vModel`) in JSX, but you can use kebab-case too (`v-model`).
  24. ```js
  25. export default {
  26. data: () => ({
  27. test: 'Hello World',
  28. }),
  29. render(h) {
  30. return (
  31. <div>
  32. <input type="text" vModel_trim={this.test} />
  33. {this.test}
  34. </div>
  35. )
  36. },
  37. }
  38. ```