• Vue 第十二章 命名视图实现经典布局


    1、命名视图

      routes:[
                    {
                        path:'/',components:{
                            default:header,
                            'left':leftBox,
                            'main':mainBox
                        }
                    }
                ]

    2、案例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <!--cdn镜像快速导入Vue包-->
        <script src="https://cdn.bootcss.com/vue/2.6.11/vue.js"></script>
        <script src="https://cdn.bootcss.com/vue-router/3.1.3/vue-router.js"></script>
    
        <style>
            .header{
                background-color: orange;
                height: 80px;
            }
            .container{
                display: flex;
                height: 700px;
            }
            .left{
                background-color: lightblue;
                flex: 2;
            }
            .main{
                background-color: lightpink;
                flex: 8;
            }
        </style>
    </head>
    <body>
    <div id="app">
        <router-view ></router-view>
        <div class="container">
    <!--        一个router-view占用一个组件的视图-->
            <router-view name="left"></router-view>
            <router-view name="main"></router-view>
        </div>
    </div>
    <script>
    
        var header = {
            template:'<h1 class="header">Header头部区域</h1>'
        }
    
        var leftBox = {
            template:'<h1 class="left">Left部区域</h1>'
        }
    
        var mainBox = {
            template:'<h1 class="main">mian部区域</h1>'
        }
    
        var router = new VueRouter({
                routes:[
                    {
                        path:'/',components:{
                            default:header,
                            'left':leftBox,
                            'main':mainBox
                        }
                    }
                ]
        })
        //2.创建一个vue实例
        var vm = new Vue({
            el: '#app',    //表示当前我们new的这个Vue实例,要控制页面上的哪个区域
            data: { //data属性中存放的是el中要用到的数据
                msg: '欢迎学习Vue' //通过Vue提供的指令,很方便的就能把数据渲染到页面上,程序
            },
            router
        })
    </script>
    </body>
    </html>
  • 相关阅读:
    Ubuntu虚拟机磁盘空间不足的解决
    eclipse启动报错 JVM terminated. Exit code=1
    Ubuntu16.04 安装eclipse
    HDU 1710 Binary Tree Traversals(二叉树)
    Ubuntu16.04 搭建伪分布式Hadoop环境
    HDU 1560 DNA sequence(IDA*)
    Go的函数
    Go的包
    Go语言开发环境搭建
    go的循环
  • 原文地址:https://www.cnblogs.com/ywjfx/p/12562149.html
Copyright © 2020-2023  润新知