1. App.vue ( 부모 컴포넌트 )
<template>
<div id="app">
<Person
username = "펭수"
age = 5
address = "EBS 소품실 한구석"
/>
<!-- age와 address를 지정하지않음 -->
<Person
username = "뽀로로"
/>
</div>
</template>
<script>
import Person from './components/Person.vue'
export default {
name: 'App',
components: {
Person
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
components / Person.vue ( 자식 컴포넌트 )
<template>
<div>
<p>{{ username }} , {{ age }} , {{ address }}</p>
</div>
</template>
<script>
export default {
name: 'Person',
props: {
username: String,
age: {
type: Number,
default: 100 // 받는 데이터가 없을 경우의 default값지정 가능
},
address: {
type: String,
default: '제주' // 받는 데이터가 없을 경우의 default값지정 가능
}
}
}
</script>
<style scoped>
</style>
완성 하였으면 터미널에서
yarn serve 하여 확인!
'웹프로그래밍 무작정따라하기 > VUE' 카테고리의 다른 글
[ VUE ] bookList 만들기 / v-for 리스트렌더링 예제 (0) | 2020.12.14 |
---|---|
[ VUE ] data 및 props 속성 / 배열, 객체, 클래스(*.js) (0) | 2020.12.11 |
[ VUE ] props속성 - 부모에서 자식으로 데이터 전송 (0) | 2020.12.11 |
[ VUE ] - 기본 구조 (0) | 2020.12.11 |
댓글