路由-使用命名试图实现经典布局

<!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>
    <script src="../../js/vue.js"></script>
    <script src="../../js/vue-router-3.0.1.js"></script>
    <style>
        .h{
    
    
            width: 100%;
            height: 50px;
            background-color: coral;
        }
        .l{
    
    
            width: 50%;
            height: 150px;
            float: left;
            background-color: cornflowerblue;
        }
        .r{
    
    
            width: 50%;
            height: 150px;
            float: left;
            background-color: cyan;
        }
    </style>
</head>
<body>
    <div id="app">
            <router-view ></router-view>
            <router-view name="left"></router-view>
            <router-view name="right"></router-view>
    </div>
    <script>
        var login={
    
    
            template:'<h1 class="h">头部</h1>'
        }
        var mleft={
    
    
            template:'<h1 class="l">左边</h1>'

        }
        var mright={
    
    
            template:'<h1 class="r">右边</h1>'
        }
        var ru=new VueRouter({
    
    
            routes:[
                {
    
    path:'/',components:{
    
    
                    'default':login,
                    'left':mleft,
                    'right':mright
                }}
            ]
        })

        var vm=new Vue({
    
    
            el:'#app',
            data:{
    
    

            },
            router:ru,
            methods: {
    
    
                
            },
          
        })
    </script>
</body>
</html>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41309350/article/details/122568937