zoukankan      html  css  js  c++  java
  • vue--路由嵌套

    路由嵌套的SPA实现的步骤:

    A(/a)组件需要嵌套B组件(/b)和C组件(/c)

    ①准备嵌套其它组价的父组件 指定一个容器
    在A组件指定一个容器
    <router-view></router-ivew>

    ②在A组件的路由配置对象中指定children属性
    {
    path:'/a',
    component:A,
    children:[
    {path:'/b',component:B},
    {path:'/c',component:C},
    ]
    }


    补充:
    //数字如果超出记录的次数,是不行的。
    this.$router.go(num);
    如果num是正数,向前进
    如果num是负数,向后退

    <!doctype html>
    <html>
     <head>
      <meta charset="UTF-8">
      <title>路由嵌套</title>
        <script src="js/vue.js"></script>
        <script src="js/vue-router.js"></script>
     </head>
     <body>
      <div id="container">
            <p>{{msg}}</p>
            <router-view></router-view>
        </div>
        <script>
    //登录组件
            var myLogin = Vue.component("login",{
                template:`
                    <div>
                        <h1>登录组件</h1>
                        <router-link to="/mail">登录</router-link>
                    </div>
            `
            })
    //    邮箱页面
            var myMail = Vue.component("mail",{
    //        定义一个返回的方法
                methods:{
                    goBack:function(){
                        this.$router.go(-1);
                    }
                },
                template:`
                    <div>
                        <h1>邮箱主页面</h1>
                        <ul>
                            <li>
                                <router-link to="/inbox">收件箱</router-link>
                            </li>
                            <li>
                                <router-link to="/outbox">发件箱</router-link>
                            </li>
                        </ul>
    //                点击按钮返回前面的页面
                        <button @click="goBack">返回</button>
                        <router-view></router-view>
                    </div>
            `
    //    指定一个容器,加载收件箱或收件箱的列表
            })
    //    收件箱组件
            var myInBox = Vue.component("inbox-component",{
                template:`
                    <div>
                        <h4>收件箱</h4>
                        <ul>
                            <li>未读邮件1</li>
                            <li>未读邮件2</li>
                            <li>未读邮件3</li>
                        </ul>
                    </div>
            `
            })
    //    发件箱组件
            var myOutBox = Vue.component("outbox-component",{
                template:`
                    <div>
                        <h4>发件箱</h4>
                        <ul>
                            <li>已发送邮件1</li>
                            <li>已发送邮件2</li>
                            <li>已发送邮件3</li>
                        </ul>
                    </div>
            `
            })
            //配置路由词典
            new Vue({
                router:new VueRouter({
                    routes:[
                        {path:'',redirect:'/login'},
                        {path:'/login',component:myLogin},
                        {path:'/mail',component:myMail,children:[
                            {path:'/inbox',component:myInBox},
                            {path:'/outbox',component:myOutBox}
                    ]},
                    ]
                }),
                el:"#container",
                data:{
                    msg:"Hello VueJs"
                }
            })
            //通过再次指定一个<router-view></router-view>和children:[]
        </script>
     </body>
    </html>
  • 相关阅读:
    Quartz使用总结(转)
    JAVA中使用LOG4J记录日志
    Java用HttpsURLConnection访问https网站的时候如何跳过SSL证书的验证?
    JAVA_HOME设置
    命令行启停mysql数据库
    本地jar包引入到maven项目中
    Could not clean server of obsolete files
    python基础一
    11-数据的增删改
    10-外键的变种 三种关系
  • 原文地址:https://www.cnblogs.com/wangruifang/p/7776934.html
Copyright © 2011-2022 走看看