Skip to content

useVModels

Category
Export Size
567 B
Last Changed
6 months ago
Related

propsv-model 绑定的简写方式。可以将其视为 toRefs(props),但是对属性的更改也会触发 emit

用法

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

类型声明

typescript
/**
 * 用于 props 的 v-model 绑定的简写。类似于 `toRefs(props)`,但更改也会触发 emit。
 *
 * @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

SourceDocs

贡献者

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

变更日志

v10.5.0 on 10/7/2023
51f01 - fix: type error with passive: true (#3362)

Released under the MIT License.