【问题标题】:Router View in a child of a component doesn't work组件子组件中的路由器视图不起作用
【发布时间】:2018-05-16 05:58:15
【问题描述】:

我正在尝试在我的路由器文件中使用此结构:

{
  path: '/',
  name: 'Dashboard',
  component: Dashboard,
  children: [
    { path: 'users', name: 'Users', component: Users },
    { path: 'permissions', name: 'Permissions', component: Permissions },
    { path: 'systems', name: 'Systems', component: Systems }
  ]
},

但它不起作用。 url 路径发生变化,但组件没有渲染。

我的 Dashboard 组件模板是这样的:

<template>
<div class="container-fluid" data-ma-theme="green">
  <main class="main">
    <header-layout></header-layout>
    <aside-layout></aside-layout>
    <content-layout></content-layout>
  </main>
</div>
</template>

我的路由器视图在内容组件中是这样的:

<template>
   <section class="content">
    <VuePerfectScrollbar class="scroll-area" v-once :settings="settings">
       <router-view/>
    </VuePerfectScrollbar>
  </section>
</template>

我不知道如何告诉仪表板路径孩子在内容组件中

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    &lt;router-view/&gt; 放在组件模板内而不是子标签内。这个&lt;VuePerfectScrollbar/&gt; 将替换为您的组件模板。意味着所有其他内容都将丢失

    VuePerfectScrollbar 模板内

    <template>
    <div>
       Other things
        ..............
        <router-view/>
        .......
        Other things
    </div>
    </template>
    

    【讨论】:

    • 非常感谢!这行得通!发生这种情况是因为 vueperfectscrollbar 内部有一个模板,不是吗?仪表板组件的上下文丢失了吗?
    猜你喜欢
    • 1970-01-01
    • 2016-09-04
    • 2021-02-07
    • 2019-02-06
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2020-04-15
    相关资源
    最近更新 更多