๐ Reference
๐ย Chapter
<script setup>
๊ตฌ๋ฌธ์์ ์ปดํฌ๋ํธ์ ์ธํฐํ์ด์ค(Props์ Emits)๋ฅผ ์ ์ํ๋ ๋ฐ ์ฌ์ฉ๋๋ ์ปดํ์ผ๋ฌ ๋งคํฌ๋ก(Compiler Macros)์ด๋ค.<script setup>
์ ์ฒ๋ฆฌํ ๋ ์ฌ์ฉํ๋ ๋น๋ ์๊ฐ ์ ์ฉ ์ ์ธ์ด๋ค.defineProps
๋ ์ปดํฌ๋ํธ๊ฐ ๋ถ๋ชจ๋ก๋ถํฐ ๋ฐ์ ์ ์๋ ์์ฑ(Props)์ ์ ์ธํ๋ค.<script setup>
// ๋ฐํ์ ๊ฐ ์ถ๋ก ์ ์ํ ๊ฐ์ฒด ์ ๋ฌ (JavaScript ๋ฐฉ์)
const props = defineProps({
// ํ์
: String, ํ์ ์ฌ๋ถ: ํ์
title: {
type: String,
required: true
},
// ํ์
: Number, ๊ธฐ๋ณธ๊ฐ: 0
count: {
type: Number,
default: 0
}
});
// props.title ๋๋ props.count์ ๊ฐ์ด ๋ด๋ถ์์ ์ฌ์ฉ
console.log(props.title);
</script>
<script setup lang="ts">
// ๐ก defineProps ๋ค์ ์ ๋ค๋ฆญ(Generic)์ผ๋ก ํ์
์ ์ ๋ฌ
const props = defineProps<{
title: string;
count?: number; // ?๋ฅผ ์ฌ์ฉํ์ฌ ์ ํ์ (optional) ์์ฑ ์ ์
}>();
// props.title์ string ํ์
์ผ๋ก ์๋ ์ถ๋ก ๋จ
</script>