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')
  },
}

Type Declarations

/**
 * Shorthand for v-model binding, props + emit -> ref
 *
 * @see   {@link /useVModel}
 * @param props
 * @param key
 * @param emit
 */
export declare function useVModel<P extends object, K extends keyof P>(
  props: P,
  key: K,
  emit?: (name: string, value: any) => void
): WritableComputedRef<P[K]>

Source

SourceDocs