Vue · Junior · Question 35 of 75

How does a parent use v-model on a custom component (Vue 3.4+)?

<!-- Child.vue -->
<script setup>
const model = defineModel();
</script>
<template><input v-model="model" /></template>

<!-- parent: <Child v-model="text" /> -->

Explanation

defineModel declares a modelValue prop and an update:modelValue event under the hood. Named models are supported too: v-model:title with defineModel('title').

Further reading

Problem with a question

Vue · Junior · question 35

Test yourself

Take the Vue · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz