คอมโพเนนต์ คือชิ้นส่วน UI ที่นำกลับมาใช้ได้และอิสระตัวเอง Props คือวิธีที่คอมโพเนนต์แม่ส่งข้อมูล ลง ไปยังคอมโพเนนต์ลูก — เป็นอินพุตที่กำหนดประเภทและอ่านได้อย่างเดียวของลูก
การกำหนด props ในคอมโพเนนต์ลูก
<!-- UserCard.vue -->
<script setup>
// declare props with types, requirements, and defaults
const props = defineProps({
name: { type: String, required: true },
age: { type: Number, default: 0 },
isAdmin: { type: Boolean, default: false },
});
</script>
<template>
<div class="card">
<h2>{{ name }}</h2> <!-- use props directly in the template -->
<p>Age: {{ age }}</p>
</div>
</template>
