Consider a Vue 3 component MyInput that uses modelValue as the prop and emits update:modelValue. If you use v-model:customValue on MyInput but the component only listens to modelValue, what will be the displayed value?
<template> <MyInput v-model:customValue="text" /> <p>{{ text }}</p> </template> <script setup> import { ref } from 'vue' import MyInput from './MyInput.vue' const text = ref('hello') </script> <!-- MyInput.vue --> <template> <input :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" /> </template> <script setup> const props = defineProps({ modelValue: String }) </script>
Check if the prop and event names match the v-model argument.
Using v-model:customValue expects the component to accept a prop named customValue and emit update:customValue. Since MyInput only uses modelValue and update:modelValue, the modelValue prop is not bound, so the input shows empty but changes do not update the parent.
You want to create a component that uses v-model:checked where the prop is checked and the event is update:checked. Which code snippet correctly defines this?
The prop and event names must match the v-model argument.
For v-model:checked, the component must accept a prop named checked and emit update:checked. Option A matches this pattern.
count after clicking the button twice in this custom v-model component?Given the parent uses v-model:count with Counter component that emits update:count on button click, what is the final value of count?
<template> <Counter v-model:count="count" /> <p>{{ count }}</p> </template> <script setup> import { ref } from 'vue' import Counter from './Counter.vue' const count = ref(0) </script> <!-- Counter.vue --> <template> <button @click="$emit('update:count', count + 1)">Increment</button> </template> <script setup> const props = defineProps({ count: Number }) </script>
Check if the component uses the prop value correctly inside the emit.
The count in the template is undefined because const props = defineProps() does not expose props directly to the template scope. Thus, count + 1 is NaN, emitted on each click, so the parent count becomes NaN.
Analyze the code below. The parent uses v-model:inputValue but typing in the input does not update the parent. What is the cause?
<template> <input :value="inputValue" @input="$emit('update:modelValue', $event.target.value)" /> </template> <script setup> const props = defineProps({ inputValue: String }) </script>
Check if the event name matches the prop name for the custom v-model.
For v-model:inputValue, the component must emit update:inputValue. Emitting update:modelValue breaks the binding.
When a component uses multiple v-model bindings like v-model:title and v-model:description, how does Vue 3 manage these bindings internally?
Think about how Vue matches prop names and event names for each v-model argument.
Vue 3 supports multiple v-model bindings by creating separate props and events for each argument. For example, v-model:title uses prop title and event update:title, and similarly for description.