Component là các phần UI tái sử dụng, độc lập. Props là cách một component cha truyền dữ liệu xuống cho component con — chúng là các đầu vào có kiểu, chỉ đọc của component con.
Khai báo props trong component con
<!-- UserCard.vue -->
<script setup>
// khai báo props với kiểu, yêu cầu bắt buộc, và giá trị mặc định
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> <!-- dùng props trực tiếp trong template -->
<p>Age: {{ age }}</p>
</div>
</template>
