Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 614 Bytes

index.md

File metadata and controls

37 lines (27 loc) · 614 Bytes
category
Component

useVModel

Shorthand for v-model binding, props + emit -> ref

Usage

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>

<script lang="ts" setup>
import { useVModel } from '@vueuse/core'

const props = defineProps<{
  modelValue: string
}>()
const emit = defineEmits(['update:modelValue'])

const data = useVModel(props, 'modelValue', emit)
</script>