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" /> -->- ✓Correct answer: With
defineModel(), which returns a ref synced with the parent'sv-model - 2Custom components can't use
v-model - 3By declaring a
valueprop and aninputevent like in Vue 2
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').