๋ชฉ์ฐจ
์ปดํฌ๋ํธ ๋ฑ๋ก
์ ์ญ ์ปดํฌ๋ํธ ๋ฑ๋ก(ํ๋ฌ๊ทธ์ธ์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํํ๋ก ์ฌ์ฉ ์)
Vue.component('app-header', {
template: '<header>header</header>'
});
์ง์ญ ์ปดํฌ๋ํธ ๋ฑ๋ก(์ผ๋ฐ์ ์ธ ์ปดํฌ๋ํธ)
1.
new Vue({
el: '#app2',
//์๋ components(s๋ถ์ฌ์ผ ํจ) ์์ฑ ์ด์ฉ(๋ณต์ )
components: {
'app-footer': {
template: '<footer>footer</footer>'
}
}
})
2.
//๊ฐ๋
์ฑ์ ์ํด ์ปดํฌ๋ํธ ๋ด์ฉ์ object๋ฅผ ๋ง๋ค์ด์ ์ ๋ฌ
let appFooter = {
template: '<footer>footer</footer>'
}
new Vue({
el: '#app2',
components: {
'app-footer': appFooter
}
})
์ง์ญ์ปดํฌ๋ํธ๋ ์ธ์คํด์คํธ๋ฅผ ์ ์ฉํ ์๋ฆฌ๋จผํธ์์์๋ง ์ ์ฉ๋จ
<div id="app">
<app-header></app-header>
<app-footer></app-footer>
</div>
<!-- <app-header>(์ ์ญ ์ปดํฌ๋ํธ)๋ #app2์ ์ ์ฉ์ด ๋์ง๋ง
<app-footer>(์ง์ญ ์ปดํฌ๋ํธ)๋ ์ ์ฉ๋์ง ์๊ณ ์๋ฌ ๋ฐ์(Unknown custom element: <app-footer>...) -->
<div id="app2">
<app-header></app-header>
<app-footer></app-footer>
</div>
์ปดํฌ๋ํธ ์ ์ฉ
<div id="app">
<!-- ์คํฌ๋ฆฝํธ์์ ๋ฑ๋กํ ์ปดํฌ๋ํธ๋ช
์ผ๋ก ํ๊ทธ๋ฅผ ์ค์ -->
<app-header></app-header>
</div>
์ ์ฒด์ฝ๋
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue Componet</title>
</head>
<body>
<!-- #app์ root component -->
<div id="app">
<!-- ์๋์์ ์์ฑํ ์ปดํฌ๋ํธ๋ฅผ ์ ์ฉ(ํ์/์์ ์ปดํฌ๋ํธ) -->
<app-header></app-header>
<!-- ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ ํํ์ -->
<h2>{{ message }}</h2>
<app-content></app-content>
<app-footer></app-footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
//์ ์ญ ์ปดํฌ๋ํธ ์์ฑ(1๋ฒ ์งธ ์ธ์: ์ปดํฌ๋ํธ๋ช
, 2๋ฒ ์งธ ์ธ์: ๊ฐ์ฒด(์ปดํฌ๋ํธ ๋ด์ฉ, template ์์ฑ ์ด์ฉ))
Vue.component('app-header', {
template: '<header>header</header>'
});
Vue.component('app-content', {
template: '<article>content</article>'
});
new Vue({
el: '#app',
//์ง์ญ ์ปดํฌ๋ํธ ๋ฑ๋ก
components: {
'app-footer': {
template: '<footer>footer</footer>'
}
},
//๋ฐ์ดํฐ ์ธํ
data: {
message: 'Hello Vue.js!!!!!!!'
}
})
</script>
</body>
</html>
๊ฒฐ๊ณผ
Root ์ปดํฌ๋ํธ๋ฅผ ๊ธฐ์ค์ผ๋ก ๊ณ์ธต๊ตฌ์กฐ๋ฅผ ์ด๋ฃธ
image source: https://v2.ko.vuejs.org/v2/guide/components.html
์ปดํฌ๋ํธ — Vue.js
Vue.js - ํ๋ก๊ทธ๋ ์๋ธ ์๋ฐ์คํฌ๋ฆฝํธ ํ๋ ์์ํฌ
v2.ko.vuejs.org
- ๋ถ๋ชจ ์ปดํฌ๋ํธ์์ ์์ ์ปดํฌ๋ํธ๋ก๋ props ์์ฑ์ผ๋ก ๋ฐ์ดํฐ ์ ๋ฌ
- ์์ ์ปดํฌ๋ํธ์์ ๋ถ๋ชจ ์ปดํฌ๋ํธ๋ก๋ event๋ก ๋ฐ์ดํฐ ์ ๋ฌ
ํต์ ๊ท์น์ด ์์ผ๋ฉด ๋ฐ์ดํฐ ํ๋ฆ ์ถ์ ์ด ์ฉ์ดํจ
reference: https://www.inflearn.com/course/age-of-vuejs/dashboard
Vue.js ์์ํ๊ธฐ - Age of Vue.js - ์ธํ๋ฐ | ๊ฐ์
Vue.js๋ก ์ฝ๊ฒ ์น ๊ฐ๋ฐํ ์ ์๋๋ก ๊ธฐ๋ณธ ๊ฐ๋ ๊ณผ ํต์ฌ ๊ธฐ๋ฅ์ ๋ํด์ ํ์ตํ๊ณ ๊ตฌํํด๋ด ๋๋ค. ๊ฐ์ข๋ฅผ ๋ค์ผ์๊ณ ๋๋ฉด Vue.js๋ก ํ๋ฐํธ์๋ ๊ฐ๋ฐ์ ํ์๋๊ฒ ์ฌ๋ฐ์ด์ง๊ฑฐ์์., [์ฌ์ง] Vue.js ์์ํ๊ธฐ,Ag
www.inflearn.com
'IT > development' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Vue.js] event emit(์์ โ ๋ถ๋ชจ) (0) | 2023.07.26 |
---|---|
[Vue.js] Props(๋ถ๋ชจ -> ์์) (0) | 2023.07.26 |
[Vue.js] ์ธ์คํด์ค์ ์์ฑ์ (0) | 2023.07.26 |
[Vue.js] ์ปดํฌ๋ํธ๋ผ๋ฆฌ์ ๋ฐ์ดํฐ ์ ๋ฌ(feat. props, event emit) (0) | 2023.07.26 |
[JavaScript] ๋๋ฑ์ฐ์ฐ์(==, !=)์ ์ผ์น์ฐ์ฐ์(===, !==) (0) | 2023.07.24 |
๋๊ธ