zoukankan      html  css  js  c++  java
  • 嵌套路由的坑

    嵌套路由就是路由里面嵌套他的子路由,可以有自己的路由导航和路由容器(router-link、router-view),通过配置children可实现多层嵌套

    //mine组件
    <template>
        <div class="content">
            在mine的组件里面嵌套路由
            <router-link to="/mine/c">去到Cpage</router-link>
            <router-link to="/mine/d">去到Dpage</router-link>
            <div class="child">
                <router-view></router-view>
            </div>
        </div>
    </template>
    //router.js
    //引入需要的组件,下是我的路径
    import Vue from 'vue'
    import Router from 'vue-router'
    import Home from '@/components/home'
    import Mine from '@/components/mine'
    import Cpage from '@/page/mine/c'
    import Dpage from '@/page/mine/d'
    Vue.use(Router)
    
    export default new Router({
      routes: [
        {   
            path: '/',
            redirect: 'home'
        },
        {
          path: '/home',
          name: 'home',
          component: Home
        },
        {
          path: '/mine',
          name: 'Mine',
          component:Mine,
          children:[
            {
                path:'/',
                component:Cpage,
            },
            {
                path:'/mine/c',
                component:Cpage,
            },
            {
                path:'/mine/d',
                component:Dpage,
            }
          ]
          //children这是嵌套的部分
        },

      

    //c.vue
    <template>
        <div class="top-80">
            c.vue
            <p>这里Cpage文件</p>
        </div>
    </template>
    
    
    //d.vue
    <template>
        <div class="top-80">
            d.vue
            <p>这里Dpage文件</p>
        </div>
    </template>

     我所遇到的坑

    //route.js
    const App = () => import('../App.vue');
    const Login = () => import('../component/Login.vue');
    const Class = () => import('../component/Class.vue');
    const CourseList = () => import('../component/CourseList.vue');
    const CourseContent = () => import('../component/CourseContent.vue');
     
    const routers = [{
        path:'/',
        component:App,
        children:[{
                path:'login',
                component:Login
            },{
                path:'class',
                component:Class
            },
            { 
                path:'course',
                children:[{
                        path:'list',
                        component:CourseList
                    },{
                        path:'content',
                        component:CourseContent
                    }
                ]
                 
            },
        ]
    }]
     
    export default routers

    当你访问的时候,发现
    http://localhost:8080/#/login
    http://localhost:8080/#/class
    都正常,但是:
    http://localhost:8080/#/course/list
    http://localhost:8080/#/course/content
    都是一片空白,检查元素,发现没有加载过来。检查,子路由前面并没有加/,所以这没有问题,排除。
    其实这是list的父级course没有component,有了componnet,并且需要在这个component里面要有<router-view></router-view> 

  • 相关阅读:
    架构、框架、组件、插件浅谈理解
    JAVA : 关于高内聚与低耦合
    windows 使用VMWARE 安装mac os
    JAVA 多线程(6):等待、通知 (1)
    JAVA 多线程(5)
    Django 笔记(六)mysql增删改查
    CSS选择器
    ubuntu 安装配置 mysql
    Django 笔记(五)自定义标签 ~ 映射mysql
    Django 笔记(四)模板标签 ~ 自定义过滤器
  • 原文地址:https://www.cnblogs.com/hy96/p/13121819.html
Copyright © 2011-2022 走看看