shortVmodel
Stability:
stableA shorthand for v-model.
v-model -> :: / $ / *
If you have any questions about this feature, you can comment on RFC Discussion.
| Features | Supported |
|---|---|
| Vue 3 | ✅ |
| Nuxt 3 | ✅ |
| Vue 2 | ❌ |
| Volar Plugin | ✅ |
Setup
Installation
bash
npm i -D @vue-macros/short-vmodelVite Integration
ts
// vite.config.ts
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import { transformShortVmodel } from '@vue-macros/short-vmodel'
export default defineConfig({
plugins: [
Vue({
template: {
compilerOptions: {
nodeTransforms: [
transformShortVmodel({
prefix: '$',
}),
],
},
},
}),
],
})Options
prefix: '::' | '$' | '*', defaults to '$'
Usage
$ Dollar Sign (Default)
vue
<template>
<input $="msg" />
<!-- => <input v-model="msg" /> -->
<demo $msg="msg" />
<!-- => <input v-model:msg="msg" /> -->
</template>:: Double Binding
vue
<template>
<!-- prettier-ignore -->
<input ::="msg" />
<!-- => <input v-model="msg" /> -->
<demo ::msg="msg" />
<!-- => <input v-model:msg="msg" /> -->
</template>* Asterisk Sign
vue
<template>
<input *="msg" />
<!-- => <input v-model="msg" /> -->
<demo *msg="msg" />
<!-- => <input v-model:msg="msg" /> -->
</template>Volar Configuration
jsonc
// tsconfig.json
{
"vueCompilerOptions": {
"plugins": [
"@vue-macros/volar/short-vmodel"
// ...
],
"vueMacros": {
"shortVmodel": {
"prefix": "$"
}
}
}
}Known Issues
- Prettier will format
::=to:=, prettier-ignore is required if prefix is::.