组件嵌套

组件嵌套

<!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>
    <!-- 引入vue.js -->
    <script src="./vue.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .container{
            width:100vw;
            height: 100vh;
            background: grey;
            display: flex;
            flex-direction: column;
        }
        .header{
            height:100px;
            background: greenyellow;
        }
        .main{
            flex:1;
            background: tomato;
            display: flex;
        }
        .left{
            width: 200px;
            background: turquoise;
        }
        .right{
            flex:1;
        }
        .footer{
            height:100px;
            background: yellowgreen;
        }
    </style>
</head>
<body>
    <!-- 作用域 -->
    <div id="app">
       
    </div>

    <!-- 标签模板 page组件 -->
    <template id="page">
        <div class="container">
            <v-header></v-header>
            <v-main></v-main>
            <v-footer></v-footer>
        </div>
    </template>

    <!-- 标签模板 header组件 -->
    <template id="header">
        <div class="header">
            header
        </div>
    </template>

    <!-- 标签模板 main组件 -->
    <template id="main">
        <div class="main">
           <v-left></v-left>
           <v-right></v-right>
        </div>
    </template>

    <!-- 标签模板 footer组件 -->
    <template id="footer">
        <div class="footer">
            footer
        </div>
    </template>

    <!-- 标签模板  left组件 -->
    <template id="left">
        <div class="left">
            left
        </div>
    </template>

    <!-- 标签模板  right组件 -->
    <template id="right">
        <div class="right">
            right
        </div>
    </template>
    <script>
        const vLeft = {
                        template:'#left'
                    }
        const vRight = {
                            template:'#right'
                        }
        const vHeader = {
                            template:'#header'
                        }
        const vMain = {
                        template:'#main',
                        components:{
                            // 左侧组件
                            vLeft,
                            //右侧组件
                            vRight,
                        }
                    }
        const vFooter = {
                            template:'#footer'
                        }
        const vPage = {
                        template:'#page',
                        components:{
                            // 头部组件
                            vHeader,
                            // 中间组件
                            vMain,
                            // 底部组件
                            vFooter,
                        }
                    }
        // 实例化vue
        new Vue({
            el:'#app',
            data:{},
            methods:{},
            components:{
                vPage
            },
            template:'<v-page></v-page>',
        })
    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值