Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useVModels.md
1---2category: Component3related: useVModel4---56# useVModels78Shorthand for props v-model binding. Think it like `toRefs(props)` but changes will also trigger emit.910## Usage1112```ts13import { useVModels } from '@vueuse/core'1415const props = defineProps({16foo: string,17bar: number,18})1920const emit = defineEmits(['update:foo', 'update:bar'])2122const { foo, bar } = useVModels(props, emit)23```2425### Options API2627```ts28import { useVModels } from '@vueuse/core'2930export default {31props: {32foo: String,33bar: Number,34},35setup(props, { emit }) {36const { foo, bar } = useVModels(props, emit)3738console.log(foo.value) // props.foo39foo.value = 'foo' // emit('update:foo', 'foo')40},41}42```4344## Type Declarations4546```ts47/**48* Shorthand for props v-model binding. Think like `toRefs(props)` but changes will also emit out.49*50* @see https://vueuse.org/useVModels51* @param props52* @param emit53* @param options54*55* @__NO_SIDE_EFFECTS__56*/57export declare function useVModels<P extends object, Name extends string>(58props: P,59emit?: (name: Name, ...args: any[]) => void,60options?: UseVModelOptions<any, true>,61): ToRefs<P>62export declare function useVModels<P extends object, Name extends string>(63props: P,64emit?: (name: Name, ...args: any[]) => void,65options?: UseVModelOptions<any, false>,66): ToRefs<P>67```68