Skip to content

useVModels ​

Category
Export Size
567 B
Last Changed
5 months ago
Related

Shorthand for props v-model binding. Think it like toRefs(props) but changes will also trigger emit.

Usage ​

js
import { useVModels } from '@vueuse/core'

export default {
  props: {
    foo: String,
    bar: Number,
  },
  setup(props, { emit }) {
    const { foo, bar } = useVModels(props, emit)

    console.log(foo.value) // props.foo
    foo.value = 'foo' // emit('update:foo', 'foo')
  },
}

Type Declarations ​

typescript
/**
 * Shorthand for props v-model binding. Think like `toRefs(props)` but changes will also emit out.
 *
 * @see https://vueuse.org/useVModels
 * @param props
 * @param emit
 * @param options
 */
export declare function useVModels<P extends object, Name extends string>(
  props: P,
  emit?: (name: Name, ...args: any[]) => void,
  options?: UseVModelOptions<any, true>,
): ToRefs<P>
export declare function useVModels<P extends object, Name extends string>(
  props: P,
  emit?: (name: Name, ...args: any[]) => void,
  options?: UseVModelOptions<any, false>,
): ToRefs<P>

Source ​

Source • Docs

Contributors ​

Anthony Fu
Mikhailov Nikita
Jelf
sondh0127
William T. Kirby
Alex Kozack
ordago
Emīls Gulbis

Changelog ​

v10.5.0 on 10/7/2023
51f01 - fix: type error with passive: true (#3362)
v8.9.3 on 7/14/2022
71550 - fix(useVModel)!: rename type VModelOptions to UseVModelOptions (#1894)

Released under the MIT License.