【问题标题】:Why is not working my nested submenu in vue-router?为什么我的嵌套子菜单不能在 vue-router 中工作?
【发布时间】:2021-09-25 17:45:44
【问题描述】:

当我点击子菜单项 javascript 时,它没有显示组件 JavaScript.vue

[
{
  path: "/",
  name: "home",
  component: Home
},
{
  path: "/guide",
  name: "guide",
  component: () => import("./components/Guide.vue"),
  children: [
    {
      path: "/guide/javascript",
      name: "javascript",
      component: () => import("./components/JavaScript.vue")
    }
  ]
},
{
  path: "/service",
  name: "service",
  component: () => import("./components/Service.vue")
},
{ path: "*", component: () => import("./components/404.vue") }
]

我在CodeSandbox中有我的代码示例

【问题讨论】:

    标签: vue.js vue-router single-page-application


    【解决方案1】:

    javascript 路由是子路由,它需要在父组件(Guide.vue)中有一个<router-view>

    添加<router-view> 来解决问题:

    <!-- Guide.vue -->
    <template>
      <div class="hello">
        <h1>Guide</h1>
        <Top />
    
        <router-view />
      </div>
    </template>
    

    demo

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 2016-10-02
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2020-06-04
      • 2017-04-17
      相关资源
      最近更新 更多