Consider a Vue 3 component using v-model on a custom child component. What will be the value of parentValue after typing 'hello' in the input?
<template> <ChildComponent v-model="parentValue" /> <p>{{ parentValue }}</p> </template> <script setup> import { ref } from 'vue' const parentValue = ref('') </script> <!-- ChildComponent.vue --> <template> <input :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" /> </template> <script setup> const props = defineProps({ modelValue: String }) </script>
Remember that v-model on custom components uses modelValue prop and update:modelValue event by default.
Using v-model on a custom component binds the modelValue prop and listens for update:modelValue events. The child emits the updated value, so the parent parentValue updates and displays the typed text.
Vue 3 allows customizing the v-model argument name. Which code snippet correctly binds v-model:checked to a child component?
Custom v-model arguments require matching prop and event names in the child.
When using v-model:checked, the child must accept a checked prop and emit update:checked events. Option C matches this pattern correctly.
Given this parent and child component code, why does typing in the input not update parentText?
<!-- Parent.vue --> <template> <ChildComponent v-model="parentText" /> <p>{{ parentText }}</p> </template> <script setup> import { ref } from 'vue' const parentText = ref('') </script> <!-- ChildComponent.vue --> <template> <input :value="text" @input="$emit('update:modelValue', $event.target.value)" /> </template> <script setup> const props = defineProps({ text: String }) </script>
Check if the prop name and emitted event name match the v-model default.
The default v-model expects a prop named modelValue and emits update:modelValue. Here, the child uses text prop instead, so the binding does not work.
In this Vue 3 component, what will be the value of count after clicking the button two times?
<template> <button @click="increment">Click me</button> <p>{{ count }}</p> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value += 1 count.value += 1 } </script>
Each click calls increment which adds 2 to count.
The increment function adds 1 twice per click, so each click increases count by 2. After two clicks, count is 4.
Choose the most accurate description of how v-model enables two-way binding in Vue 3 components.
Think about the prop and event naming conventions v-model uses.
Vue 3's v-model works by binding a prop (default modelValue) and listening for an event (default update:modelValue) to update the parent's reactive state. It does not mutate parent state directly or use a global event bus.