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

How to use vs2019 for Linux remote development

Usually, there are two options when we develop Li...

Design a simple HTML login interface using CSS style

login.html part: <!DOCTYPE html> <html l...

A brief introduction to the command line tool mycli for operating MySQL database

GitHub has all kinds of magic tools. Today I foun...

Teach you how to use vscode to build a react-native development environment

question The code has no prompt: Many non-front-e...

Advantages and Problems of XHTML CSS Website Design

XHTML is the standard website design language cur...

jQuery plugin to implement minesweeper game (1)

This article shares the specific code of the firs...

Mysql 5.7.17 winx64 installation tutorial on win7

Software version and platform: MySQL-5.7.17-winx6...

mysql8.0 windows x64 zip package installation and configuration tutorial

MySQL 8 Windows version zip installation steps (d...

Mysql stores tree structure through Adjacency List (adjacency list)

The following content introduces the process and ...

Detailed explanation of several ways to install CMake on Ubuntu

apt install CMake sudo apt install cmake This met...

MySQL optimization: how to write high-quality SQL statements

Preface There are a lot of information and method...

A brief discussion on the design and optimization of MySQL tree structure tables

Preface In many management and office systems, tr...