javascript - vue-router2.2.0 多层路由不起效果?
阿神
阿神 2017-04-11 12:54:35
[JavaScript讨论组]
  1. 在使用vue-router的时候发现有children设置,但是设置并没有达到网上看到的效果,请问是哪里代码错误。

我访问 http://localhost:8080/#/ 出现 Hello组件

但是我访问http://localhost:8080/#/test/a 却没有出现 Test组件的内容

阿神
阿神

闭关修行中......

全部回复(1)
阿神

嵌套路由表达组件的嵌套关系,子路由a的父级并没有指定component,所以就不会有内容出现了。而且父级组件还必须包含<router-view>才行。例如:

{
    path: '/test',
    name: 'test',
    component: Test,
    children: [
        {
            path: '/a',
            name: 'a',
            component: A
        }
    ]
},

component Test:

<template>
    <p>
        <h1>this is component test</h1>
        <router-view></router-view>
    </p>
</template>

文档链接https://router.vuejs.org/zh-cn/essentials/nested-routes.html

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号