useVModel
Shorthand for v-model binding, props + emit -> ref
We encourage you to use Vue's
defineModel
over this composable, however there are some edge-cases like usingTSX
or thedeep: true
option thatdefineModel
doesn't support.
Usage
js
import { useVModel } from '@vueuse/core'
export default {
setup(props, { emit }) {
const data = useVModel(props, 'data', emit)
console.log(data.value) // props.data
data.value = 'foo' // emit('update:data', 'foo')
},
}
<script setup>
Conference Offer
Get 50% OFF a Vue School Yearly or Lifetime Plan
Access 1400+ lessons on Vue, Pinia, Vite, Tailwind + more
16hours
:
11minutes
:
52seconds
:
Conference Offer
Get 50% OFF a Vue School Yearly or Lifetime Plan
Access 1400+ lessons on Vue, Pinia, Vite, Tailwind + more
16
hours
:
11
minutes
:
52
seconds
: