Nested display implementation of vue router-view

Nested display implementation of vue router-view

1. Routing Configuration

const routes = [
  {
    path: '/',
    name: 'Navigation 1',
    component: Home,
    children:[
      {
        path: '/customer',
        name: 'Customer',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Customer.vue')
      },
      {
        path: '/pageOne',
        name: 'Page 1',
        component: PageOne,

      },
      {
        path: '/pageTwo',
        name: 'Page 2',
        component: PageTwo,
    },
    ]
  },
  {
    path: '/navigation',
    name: 'Navigation 2',
    component: Home,
    children:[
      {
        path: '/pageThree',
        name: 'Page 3',
        component: PageThree,

      },
      {
        path: '/pageFour',
        name: 'Page 4',
        component: PageFour
      },
    ]
  },

2. Vue page nesting

App.vue first configures the first router-view

// An highlighted block
 <router-view></router-view>

Home.vue configures the second router-view

// An highlighted block
<template>
  <div>
  <el-container style="height: 500px; border: 1px solid #eee">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">

      <el-menu>
        <el-submenu v-for="(item,index) in $router.options.routes" :index="index+''">
        <template slot="title"><i class="el-icon-sell"></i>{{item.name}}</template>
          <el-menu-item v-for="(item2,index2) in item.children" :index="index+'-'+index2">{{item2.name}}</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>View</el-dropdown-item>
            <el-dropdown-item>New</el-dropdown-item>
            <el-dropdown-item>Delete</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>Wang Xiaohu</span>
      </el-header>

      <el-main>
        <router-view></router-view>

      </el-main>
    </el-container>

  </el-container>

</div>
</template>

<style>
.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>

<script>
export default {

};
</script>

3. Nested Relationships

First, when you visit http://localhost:8181/, you will enter the first level of nesting, and then enter the first router-view: Home.vue. Then when pageone is accessed, Home.vue will be accessed as well.

Because the nested display of router-view is related to the nested routing path, you can see that in the routing, under the path of navigation one are the routing paths of page one and page two respectively. So when accessing page one, the parent path Home.vue page will be accessed first. If you add Home.vue page without placing router-view, the lower-level pages will not be displayed

This is the end of this article about the nested display implementation of vue router-view. For more related vue router-view nested display content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The implementation principle of Vue router-view and router-link
  • Solve the problem that the content of the reused component of vue update router-view does not refresh
  • Tutorial on using router-view component in vue
  • Vue2 sets the default path of router-view
  • Vue implements the method of having multiple router-views on the same page
  • Solution to vue2.0 routing not displaying router-view
  • Solution to router-view not rendering in vue-router
  • Implementation of nested jump of vue routing view router-view

<<:  Use Python to connect to MySQL database using the pymysql module

>>:  Install JDK8 in rpm mode on CentOS7

Recommend

Various problems encountered by novices when installing mysql into docker

Preface Recently, my computer often takes a long ...

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

How to use the jquery editor plugin tinyMCE

Modify the simplified file size and download the ...

Detailed explanation of nginx-naxsi whitelist rules

Whitelist rule syntax: BasicRule wl:ID [negative]...

About deploying a web project to Alibaba Cloud Server (5 steps to do it)

1. First log in to the Alibaba Cloud website to r...

A comprehensive understanding of Vue.js functional components

Table of contents Preface React Functional Compon...

Learn more about the most commonly used JavaScript events

Table of contents JavaScript events: Commonly use...

How does Vue track data changes?

Table of contents background example Misconceptio...

Springboot+Vue-Cropper realizes the effect of avatar cutting and uploading

Use the Vue-Cropper component to upload avatars. ...

Explanation on whether to choose paging or loading in interactive design

The author of this article @子木yoyo posted it on hi...

Steps to deploy Docker project in IDEA

Now most projects have begun to be deployed on Do...

Implementation example of Vue+Element+Springboot image upload

Recently, I happened to be in touch with the vue+...

Some suggestions on Vue code readability

Table of contents 1. Make good use of components ...