πΒ Reference
πΒ Chapter
Compiler Macro (μ»΄νμΌλ¬ λ§€ν¬λ‘)
setup
ν¨μλ₯Ό μ¬μ©ν μ μλ€.ref
λ₯Ό μ¬μ©ν΄μ λ°μν λ³μλ‘ data
λ₯Ό 보ν΅μ μλ°μ€ν¬λ¦½νΈ ν¨μλ‘ methods
λ₯Ό λ체νλ€.onMounted
, onUpdated
κ°μ λΌμ΄νμ¬μ΄ν΄ ν
ν¨μκ° λμ νλ€.watch
ν¨μλ‘ κ΅¬ν κ°λ₯νλ©° κ³μ°λ κ°μ μν computed
ν¨μλ μ 곡λλ€.setup
ν¨μ μμμ μ¬μ© κ°λ₯νλ€.setup
μ μ¬μ©νλ μ»΄ν¬λνΈλ μλμ κ°μ λ°©μμΌλ‘ μμ±νλ€.<script>
import { ref, onMounted } from 'vue'
export default {
props: {
name: String
},
setup(props) {
const isSubmited = ref(false);
const onSubmit = () => {
isSubmited.value = true;
}
onMouted(() => console.log('component mounted'));
// templateμ μ λ¬νλ€.
return {
isSubmited,
onSubmit
}
}
}
</script>
<template>
<div>{{ name }} {{ isSubmited ? 'submited' : 'not yet' }}</div>
<button @click="onSubmit">Submit</button>
</template>
setup
ν¨μλ μ»΄ν¬λνΈ μΈμ€ν΄μ€κ° μμ±λκΈ° μ μ μ€νλλ€λ μ μ΄λ€.setup
μμμΒ this
λ₯Ό ν΅ν΄ μ»΄ν¬λνΈ κ°μ²΄μΒ data
,Β computed
,Β methods
μμ μ μΈν κ²λ€μλ μ κ·Όμ΄ λΆκ°λ₯νλ€.created
λ©μλμ λ§€μΉλλ λΌμ΄ν μ¬μ΄ν΄ ν
λ μ‘΄μ¬νμ§ μλλ€.