v-model on your own component with defineModel

Vue 3.4 made two-way binding on custom components a one-liner.

SNP 079 #B41 Filed js vue

Before, you declared a modelValue prop and emitted update:modelValue. Now:

vue
<script setup>
const model = defineModel()
</script>

<template>
  <input v-model="model" />
</template>

The parent uses it like any input:

vue
<SearchField v-model="query" />

Named models work too: defineModel('checked') pairs with v-model:checked. Add a default or a type the way you would for a prop: defineModel({ type: String, default: '' }).