How does v-model work on a custom component?
Assesses fundamental understanding of Vue.js conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
v-model on a component is syntactic sugar. In Vue 3, v-model="foo" compiles to passing a modelValue prop and listening for update:modelValue. Inside the child you declare and emit it:
<script setup>
const props = defineProps(['modelValue']);
const emit = defineEmits(['update:modelValue']);
</script>
<input :value="props.modelValue" @input="emit('update:modelValue', $event.target.value)" />
Named models use an argument: v-model:title maps to the title prop and update:title event, so a component can support several two-way bindings. Vue 2 used value and input with an optional model option; Vue 3 removed that in favour of the name.
Modifiers such as v-model.trim are not applied automatically on components. The child receives them through the modelModifiers prop and must implement the behaviour. This pattern is how form libraries wrap native inputs with consistent validation and formatting.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.