<script setup> μ μ±κΈ νμΌ μ»΄ν¬λνΈ(SFC) λ΄μμ Composition API λ₯Ό λ μ½κ² μ½κ±°λ μ¬μ©νκΈ° μν μ»΄νμΌ νμ λ¬Έλ².
<script> λ¬Έλ²κ³Ό λΉκ΅ν μ₯μ
- λ κ°κ²°ν μ½λ
- μμ typescript λ₯Ό μ¬μ©νμ¬ props λ° emit μ΄λ²€νΈλ₯Ό μ μΈνλ κΈ°λ₯
- λ λμ λ°νμ μ±λ₯ => template μ μ€κ° νλ‘μ μμ΄ λμΌν λ²μμ λ λν¨μλ‘ μ»΄νμΌ λ¨
- λ λμ IDE νμ μΆλ‘ μ±λ₯ => μΈμ΄ μλ²κ° μ½λμμ νμ μ μΆμΆνλ μμ κ°μ
κΈ°λ³Έ λ¬Έλ²
# script λΈλ‘μ setup μμ± μΆκ°
<script setup>
console.log('vue.js')
</script>
π <script> μ»΄ν¬λνΈλ₯Ό μ²μ κ°μ Έμ¬ λ νλ²λ§ μ€ν λλ μ½λ </script>
<script setup >μ»΄ν¬λνΈμ μΈμ€ν΄μ€κ° μμ±λ λλ§λ€ μ€νλλ μ½λ </script>
# ν νλ¦Ώμ λ ΈμΆλλ μ΅μμ λ°μΈλ©
λ΄λΆμ μ μΈλ λͺ¨λ μ΅μμ λ°μΈλ©(λ³μ, ν¨μ μ μΈ, import) μ ν νλ¦Ώμμ μ§μ μ¬μ©ν μ μλ€.
<script setup>
//import ν¨μ
import { capitalize } from './helpers'
//λ³μ
const msg = 'hi';
//ν¨μ
function log() {
console.log(msg)
}
</script>
<template>
<div>{{ capitalize('hello') }}</div>
<button @click="log">{{ msg }}</button>
</template>
# λ°μν
ν νλ¦Ώμμ μ°Έμ‘°λ λ ref λ μλμΌλ‘ μΈλν
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<!-- ν
νλ¦Ώμμ refλ μΈλνλμ΄ .value μμ΄ μ κ·Ό κ°λ₯ -->
<button @click="count++">{{ count }}</button>
</template>
# defineProps() & defineEmits()
<script setup>
const props = defineProps({
foo: String
})
const emit = defineEmits(['change', 'delete'])
// ... setup μ½λ
</script>
π defineProps λ° defineEmits λ <script setup> λ΄μμλ§ μ¬μ©ν μ μλ μ»΄νμΌλ¬ 맀ν¬λ‘ μ΄λ€.
import ν νμ μμΌλ©°, <script setup> μ΄ μ²λ¦¬λ λ μ»΄νμΌ λλ€.
- μ λ¬λ μ΅μ μ κΈ°λ°μΌλ‘ μ μ ν νμ μΆλ‘ μ μ 곡