Good Code
The good version separates draft input from the saved value. The parent receives a single save event with the trimmed title.
Lesson 05
Keep form drafts local and emit submitted values instead of writing through props while the user types.
<script setup lang="ts">
import { ref } from "vue";
const props = defineProps<{ initialTitle: string }>();
const emit = defineEmits<{ save: [title: string] }>();
// The draft is local until the user submits the form.
const draftTitle = ref(props.initialTitle);
</script>
<template>
<form @submit.prevent="emit('save', draftTitle.trim())">
<label>
Review title
<input v-model="draftTitle">
</label>
<button type="submit">Save</button>
</form>
</template><script setup>
const props = defineProps(["review"]);
// Typing writes through the prop before the user saves.
</script>
<template>
<form>
<input v-model="props.review.title">
<button>Save</button>
</form>
</template>The good version separates draft input from the saved value. The parent receives a single save event with the trimmed title.
The bad version writes to a prop object as the user types. Cancel, validation, and optimistic update behavior become harder to reason about.