# Vue Property Decorator

μ•žμ—μ„œ μ‚΄νŽ΄λ³Έ λ·° 클래슀 μ»΄ν¬λ„ŒνŠΈ(vue-class-component (opens new window)) 라이브러리 이외에도 νƒ€μž…μŠ€ν¬λ¦½νŠΈλ‘œ λ·° μ»΄ν¬λ„ŒνŠΈλ₯Ό μž‘μ„±ν•  λ•Œ μœ μš©ν•œ λΌμ΄λΈŒλŸ¬λ¦¬κ°€ μžˆμŠ΅λ‹ˆλ‹€. λ·° ν”„λ‘œνΌν‹° λ°μ½”λ ˆμ΄ν„°(Vue Property Decorator (opens new window)) λΌμ΄λΈŒλŸ¬λ¦¬μž…λ‹ˆλ‹€.

TIP

참고둜 λ·° ν”„λ‘œνΌν‹° λ°μ½”λ ˆμ΄ν„° λΌμ΄λΈŒλŸ¬λ¦¬λŠ” λ·° 클래슀 μ»΄ν¬λ„ŒνŠΈλ₯Ό 기반으둜 μ œμž‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

# 맛보기 μ½”λ“œ

Vue Property Decoratorκ°€ 적용된 μ½”λ“œ μ˜ˆμ‹œμž…λ‹ˆλ‹€.









Β 




Β 



<!-- Child.vue -->
<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';

@Component
export default class Child extends Vue {
  // '!'λŠ” μ΄ˆκΈ°ν™” 속성에 λΆ™μ΄λŠ” prefix (νƒ€μž…μŠ€ν¬λ¦½νŠΈμ—κ²Œ 미리 μ•Œλ €μ£ΌλŠ” μ—­ν• )
  @Prop() private msg!: string;
}
</script>

μœ„ μ»΄ν¬λ„ŒνŠΈλŠ” μƒμœ„ μ»΄ν¬λ„ŒνŠΈμ—μ„œ msgλΌλŠ” props 속성을 λ‚΄λ € 받은 ν•˜μœ„ μ»΄ν¬λ„ŒνŠΈ μ½”λ“œμž…λ‹ˆλ‹€. μž„ν¬νŠΈν•œ Prop λ°μ½”λ ˆμ΄ν„°λ‘œ λ‚΄λ € 받은 props 속성을 μ •μ˜ν•΄μ£Όμ—ˆμŠ΅λ‹ˆλ‹€. λ§Œμ•½ ν”„λ‘­μŠ€ 속성에 Props Validation (opens new window)을 μ£Όκ³  μ‹Άλ‹€λ©΄ μ•„λž˜μ™€ 같이 μ •μ˜ν•˜λ©΄ λ©λ‹ˆλ‹€.

@Prop(String) private msg!: string;
@Prop([String, Number]) private msg!: string;
@Prop({ default: 'hi' }) private msg!: string;