Detailed explanation of the use of router-view components in Vue

Detailed explanation of the use of router-view components in Vue

When developing a Vue project, you often need to implement a page that can switch to display different component pages.

For example: In the figure below, by clicking on different components in the sidebar, you can be routed to different component pages, while the sidebar and the top part remain unchanged, and only the component page is switched .

Please add a description of the image

At this time, we need to use the router-view component (also called routing placeholder) in the route

First, we come to the page where we need to switch different component pages and add the router-view component where we need it.
Home.vue

<template>
<!--Header area-->
    <el-header>
      <div>
        <img class="shop" src="../assets/img/shop.png" alt="">
        <span>E-commerce backend management system</span>
      </div>
      <el-button type="info" @click="logout">Logout</el-button>
    </el-header>
    <el-container>
<!--Sidebar-->
	<!--This is simplified for easy understanding. It means clicking on different options in the sidebar to jump to the route-->
    <router-link :to="/roles"></router-link><!--Role list-->
    <router-link :to="/rights"></router-link><!--Permission list-->
<!--Route placeholder-->
    <router-view></router-view>
</template>

The route corresponding to the role list is /roles, and the route corresponding to the permission list is /rights.
After adding the router-view component, configure the route. The following is the route configuration

index.js

{
      path:'/home',
      component:Home,
      // Redirect to the role list redirect:'/roles',
      children:[
        {
          path:'/rights',
          component:Rights
        },
        {
          path:'/roles',
          component:Roles
        } 
      ]
    }

In this way, we have realized the use of the router-view component!

This is the end of this article about the detailed use of the router-view component in Vue. For more relevant content on the use of the Vue router-view component, 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:
  • Solution to router-view not rendering in vue-router
  • Solution to vue2.0 routing not displaying router-view
  • Solve the problem that the content of the reused component of vue update router-view does not refresh
  • Vue routing article router-view content cannot be rendered

<<:  What is Nginx load balancing and how to configure it

>>:  CSS uses the autoflow attribute to achieve seat selection effect

Recommend

Detailed explanation of the data responsiveness principle of Vue

This article is mainly for those who do not under...

How to convert a column of comma-separated values ​​into columns in MySQL

Preface Sometimes you come across business tables...

Detailed explanation of how to use Vue to load weather components

This article shares with you how to use Vue to lo...

Detailed explanation of the use of Vue.js render function

Vue recommends using templates to create your HTM...

MySQL 5.7.18 MSI Installation Graphics Tutorial

This article shares the MySQL 5.7.18 MSI installa...

Use PSSH to batch manage Linux servers

pssh is an open source software implemented in Py...

How to solve the mysql insert garbled problem

Problem description: When inserting Chinese chara...

When to use table and when to use CSS (experience sharing)

The main text page of TW used to have a width of 8...

A brief discussion on the optimization of MySQL paging for billions of data

Table of contents background analyze Data simulat...

Detailed explanation of VUE responsiveness principle

Table of contents 1. Responsive principle foundat...

The difference between char, varchar and text field types in MySQL

In MySQL, fields of char, varchar, and text types...

Exploration and correction of the weird behavior of parseInt() in js

Background: I wonder if you have noticed that if ...

WeChat applet realizes horizontal and vertical scrolling

This article example shares the specific code for...

JavaScript to achieve the idea of ​​​​snake game

The implementation idea of ​​the javascript game ...