跳到内容

useVModels

类别
导出大小
509 B
最后更改
4 个月前
相关

props v-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
/**
 * Shorthand for props v-model binding. Think like `toRefs(props)` but changes will also emit out.
 *
 * @see https://vueuse.org.cn/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

更新日志

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: 放弃 Vue 2 支持,优化包并清理 (#4349)
v10.5.0 on 10/7/2023
51f01 - fix: passive: true 时的类型错误 (#3362)

在 MIT 许可证下发布。