Skip to content

useVModel

Category
Export Size
486 B
Last Changed
2 months ago
Related

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 using TSX or the deep: true option that defineModel 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
Get Offer
16
hours
:
11
minutes
:
52
seconds
: