1. @vue/babel-sugar-v-model
Babel syntactic sugar for v-model support in Vue JSX
@vue/babel-sugar-v-model
Package: @vue/babel-sugar-v-model
Created by: vuejs
Last modified: Thu, 25 Aug 2022 11:55:08 GMT
Version: 1.4.0
License: MIT
Downloads: 3,831,230
Repository: https://github.com/vuejs/jsx

Install

npm install @vue/babel-sugar-v-model
yarn add @vue/babel-sugar-v-model

@vue/babel-sugar-v-model

Syntactic sugar for v-model in JSX.

Babel Compatibility Notes

Usage

Install the dependencies:

 # for yarn:
yarn add @vue/babel-sugar-v-model
# for npm:
npm install @vue/babel-sugar-v-model --save

In your .babelrc:

 {
  "plugins": ["@vue/babel-sugar-v-model"]
}

However it is recommended to use the configurable preset instead.

Details

This plugin adds v-model to the JSX and tries to mirror the same behaviour as in vue-template-compiler, with a few differences:

  1. You should use underscore (_) instead of dot (.) for modifiers (vModel_trim={this.test})
  2. It is recommended to use camelCase version of it (vModel) in JSX, but you can use kebab-case too (v-model).
 export default {
  data: () => ({
    test: 'Hello World',
  }),
  render(h) {
    return (
      <div>
        <input type="text" vModel_trim={this.test} />
        {this.test}
      </div>
    )
  },
}

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin