简体   繁体   English

vue.js - 嵌套组件体系结构中的路由

[英]vue.js - routing in nested components architecture

I use vue.js to design an administration app and I'm trying to build the UI architecture as modular as possible. 我使用vue.js设计一个管理应用程序,我正在尝试尽可能模块化构建UI架构。 So I have set up and wrapped the Header , Body , Sidebar and Main in single file components as can be seen below. 所以我在单个文件组件中设置并包装了HeaderBodySidebarMain ,如下所示。

Tree

App
- Header
  - dynamic content
- Body
  - Sidebar
    - dynamic content
  - Main
    - dynamic content

Graphical 图形

┌──────────────────────────────────────────────────────────┐
│ HEADER                              SOME DYNAMIC CONTENT │
├──────────────────────────────────────────────────────────┤
│ BODY                                                     │
│┌──────────┬─────────────────────────────────────────────┐│
││ SIDEBAR  │ MAIN                                        ││
││          │                                             ││
││ SOME     │ SOME DYNAMIC CONTENT                        ││
││ DYNAMIC  │                                             ││
││ CONTENT  │                                             ││
││          │                                             ││
│└──────────┴─────────────────────────────────────────────┘│
└──────────────────────────────────────────────────────────┘

Now each of these components has it's own router view to display dynamic content depending on the current route. 现在,每个组件都有自己的路由器视图,以根据当前路由显示动态内容。 How can I achieve this when I only have one single router-view available in vue.js? 当我在vue.js中只有一个路由器视图时,我怎样才能实现这一点? Isn't it somehow possible to address these dynamic components altogether through the routed view component without overriding the original content similar to php Smarty, like this? 是不是可能通过路由视图组件完全解决这些动态组件而不重写类似于php Smarty的原始内容,像这样?

aboutus.vue aboutus.vue

<template>
    <div>
        <header>
            <header-content>
                About us - Header
            </header-content>
        </header>
        <sidebar>
            <sidebar-content>
                About us - Sidebar
            </sidebar-content>
        </sidebar>
        <main>
            <main-content>
                About us - Main
            </main-content>
        </main>
    </div>
</template>

<script>
    /* ... */
</script>

But that would be impossible due to the nested architecture I guess? 但是,由于我认为嵌套式架构,这是不可能的? I can't find a proper way to get into this routing architecture in vue.js with nested components. 我找不到使用嵌套组件进入vue.js中的这种路由体系结构的正确方法。

I have tried achieving something similar to this, in which I have the separate component folder under which I have views folder. 我已经尝试实现类似于此的东西,其中我有单独的组件文件夹,在其下我有views文件夹。 so I imported the component in my index.js. 所以我在index.js中导入了组件。 have a look at below example, I have imported admin component under which I have added its children. 看看下面的例子,我已经导入了管理员组件,我已经添加了它的子项。 Similarly, you can add multiple children to the different component and these children will load in their parent component only. 同样,您可以将多个子项添加到不同的组件,这些子项将仅加载到其父组件中。

{
 path: '/admin',
      component: AdminComponent,
      children: [
        {
          path: 'admin_dashboard',
          alias: '',
          component: AdminDashboard,
          name: 'admin_dashboard'
        },

Take a look at this theme structure https://github.com/misterGF/CoPilot 看一下这个主题结构https://github.com/misterGF/CoPilot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM