defineModel()

Declares a two-way bindable prop for v-model in <script setup>.

Since Vue 3.4 Spec ↗

Syntax

const model = defineModel<T>(name?, options?)

Parameters

NameTypeRequiredDescription
name string No Optional model name for named v-model.
options object No Supports required, default, get, set.

Returns

ModelRef<T> — A writable ref synced with the parent v-model.

Examples

<script setup lang="ts">
const model = defineModel<string>({ default: '' });
</script>

<template>
  <input :value="model" @input="model = ($event.target as HTMLInputElement).value" />
</template>
<!-- parent -->
<!-- <MyInput v-model="text" /> -->

Notes

defineModel is a macro (no import) that creates a ref wired to the matching prop and `update:modelValue` event, so the parent can use `v-model`. Pass a name for multiple models (`v-model:title`). Writing to the ref emits the update automatically.