vue.joedoe.dev

← All the recipesComponents

v-model on your components with defineModel

One line instead of the modelValue prop, the update:modelValue emit and the computed that tied them together.

Vue SFC
<script setup lang="ts">
const count = defineModel<number>({ default: 0 });
const { min = 0, max = 10 } = defineProps<{ min?: number; max?: number }>();
</script>

<template>
	<span class="stepper">
		<button :disabled="count <= min" aria-label="Menos" @click="count--">−</button>
		<output>{{ count }}</output>
		<button :disabled="count >= max" aria-label="Más" @click="count++">+</button>
	</span>
</template>

Adultos 2

Niños 0

Sois 2.

↑↓ move · ↵ open · esc close