<Do it! Vue.js ์ ๋ฌธ>์ ๊ธฐ๋ณธ์ผ๋ก ๋ฐฐ์ด ๋ด์ฉ์ ๋๋ค.
๋ชฉ์ฐจ
- 1) Vue Componets
- 2) ์ปดํฌ๋ํธ ๋ฑ๋ก
Vue Componets
1) Vue Componets
- ํ๋ฉด์ ์์๋ค(๋ด๋น๊ฒ์ด์ ๋ฐ, ํ ์ด๋ธ, ๋ฆฌ์คํธ, input ๋ฐ์ค ๋ฑ)์ ์๊ฒ ์ชผ๊ฐ์ด ์ปดํฌ๋ํธ๋ก ๊ด๋ฆฌํ๋ค.
- ์ปดํฌ๋ํธ๋ฅผ ํ์ฉํ๋ฉด ํ๋ฉด์ ๋น ๋ฅด๊ฒ ๊ตฌ์กฐํํ์ฌ ์ผ๊ด์ ์ธ ํจํด์ผ๋ก ๊ฐ๋ฐํ ์ ์๋ค.
- ์ปดํฌ๋ํธ ๊ฐ์ ๊ด๊ณ(treeํํ)๋ ๋ทฐ์์ ํ๋ฉด์ ๊ตฌ์ฑํ๋๋ฐ ๋งค์ฐ ์ค์ํ ์ญํ ์ ํ๋ฉฐ, ์น ํ์ด์ง ํ๋ฉด์ ์ค๊ณํ ๋๋ ์ด์ ๊ฐ์ ๊ณจ๊ฒฉ์ ์ ์งํ๋ฉด์ ์ค๊ณ๋ฅผ ํด์ผ ํ๋ค.
2) ์ปดํฌ๋ํธ ๋ฑ๋ก
- ์ปดํฌ๋ํธ ์ด๋ฆ์ template์์ฑ์์ ์ฌ์ฉํ HTML ์ฌ์ฉ์ ์ ์ ํ๊ทธ ์ด๋ฆ์ ์์ฑํ๋ค.
- ์ปดํฌ๋ํธ ๋ด์ฉ์๋ ์ปดํฌ๋ํธ ํ๊ทธ๊ฐ ์ค์ ํ๋ฉด์ HTML ์์๋ก ๋ณํ๋ ๋ ํ์๋ ์์ฑ๋ค์ ์์ฑํ๊ณ , ์ธ์คํด์ค ์ต์ ์์ฑ์ ์ ์ํ ์ ์๋ค.
- ์ ์ญ ์ปดํฌ๋ํธ
- ์ฌ๋ฌ ์ธ์คํด์ค์์ ๊ณตํต์ผ๋ก ์ฌ์ฉํ ์ ์๋ค.
- ์ธ์คํด์ค๋ฅผ ์์ฑํ ๋๋ง๋ค ์ธ์คํด์ค์ components์์ฑ์ผ๋ก ๋ฑ๋กํ ํ์์์ด ํ ๋ฒ ๋ฑ๋กํ๋ฉด ๋ชจ๋ ์ธ์คํด์ค์์ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
Vue.component('์ปดํฌ๋ํธ์ด๋ฆ', {
//์ปดํฌ๋ํธ ๋ด์ฉ
});
<html>
<head>
<title>Vue Component Registration</title>
</head>
<body>
<div id="app">
<button>์ปดํฌ๋ํธ ๋ฑ๋ก</button>
<my-component></my-component> //์ ์ญ ์ปดํฌ๋ํธ ํ์
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.2/dist/vue.js"></script>
<script>
//์ ์ญ ์ปดํฌ๋ํธ ๋ฑ๋ก
Vue.component('my-component', {
template: '<div>์ ์ญ ์ปดํฌ๋ํธ๊ฐ ๋ฑ๋ก๋์์ต๋๋ค!</div>'
});
new Vue({
el: '#app'
});
</script>
</body>
</html>
- ์ง์ญ ์ปดํฌ๋ํธ
- ํน์ ์ธ์คํด์ค์์๋ง ์ ํจํ ๋ฒ์๋ฅผ ๊ฐ๋๋ค.
- ์ ์ธ์คํด์ค๋ฅผ ์์ฑํ ๋๋ง๋ค ๋ฑ๋กํด ์ค์ผ ํ๋ค.
new Vue({
components: {
'์ปดํฌ๋ํธ์ด๋ฆ': ์ปดํฌ๋ํธ ๋ด์ฉ
}
});
<html>
<head>
<title>Vue Component Registration</title>
</head>
<body>
<div id="app">
<button>์ปดํฌ๋ํธ ๋ฑ๋ก</button>
<my-local-component></my-local-component>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.2/dist/vue.js"></script>
<script>
var cmp = {
// ์ปดํฌ๋ํธ ๋ด์ฉ
template: '<div>์ง์ญ ์ปดํฌ๋ํธ๊ฐ ๋ฑ๋ก๋์์ต๋๋ค!</div>'
};
new Vue({
el: '#app',
components: {
'my-local-component': cmp
}
});
</script>
</body>
</html>
'๐ปWEB FrontEnd > ํ๋ ์์ํฌ Vue' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Vue Router (0) | 2020.07.02 |
---|---|
Vue Componets ํต์ (0) | 2020.07.02 |
Vue Instance (0) | 2020.07.01 |
Vue ์์ํ๊ธฐ (+๊ฐ๋ฐ ํ๊ฒฝ ์ค์ ) (0) | 2020.06.30 |
Vue.js๋? (0) | 2020.06.30 |