Skip to content

useVModels

类别
导出体积
567 B
上次更改
4 months ago
相关

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>

源码

源码文档

贡献者

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)