๐Ÿ“• Language/Vue

[Age of Vue] Vue.js ์‹œ์ž‘ํ•˜๊ธฐ - 13.์ปดํฌ๋„ŒํŠธ์™€ ์ธ์Šคํ„ด์Šค์™€์˜ ๊ด€๊ณ„

a n u e 2022. 5. 1. 17:07

์ง€์—ญ/์ „์—ญ ์ปดํฌ๋„ŒํŠธ์˜ ์ฐจ์ด์ ?

์ „์—ญ ์ปดํฌ๋„ŒํŠธ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ˜•์‹์œผ๋กœ ๋งŒ๋“ค์–ด ์ „์—ญ์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผํ•  ๋•Œ์—๋งŒ ์‚ฌ์šฉ. ์ „์—ญ์ด๋ฏ€๋กœ, ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๋•Œ๋งˆ๋‹ค ์ƒ์„ฑํ•ด ์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!-- ์•„๋ž˜์—์„œ ๋“ฑ๋กํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ ์šฉ์‹œํ‚ด-->
        <app-header></app-header>
        <app-footer></app-footer>
    </div>

    <div id="app2">
        <app-header></app-header>
        <app-footer></app-footer> //์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋ฉด์„œ ํ™”๋ฉด์— ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค. footer๋Š” ์ง€์—ญ ์ปดํฌ๋„ŒํŠธ์ด๊ณ  app๊ณผ ๋งคํ•‘๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        //์ „์—ญ ์ปดํฌ๋„ŒํŠธ
        Vue.component('app-header', {
            template : '<h1>Header1</h1>'
        });

        //์ง€์—ญ ์ปดํฌ๋„ŒํŠธ
        new Vue({
                el : '#app',
                components : 
                {
                    'app-footer' : {
                        template : '<footer>footer</footer>'
                    }
                }
            });

        new Vue({
            el : '#app2'
        })
    </script>
</body>
</html>