Vue router named routing and view

Vue router named routing and view

1. Naming routes

1.1 name

{
    
    
	path:'/user/:id',
	name:'user',
	component:User,
}

1.2 html mode – router-link

方式1
<router-link to="/user/123">Go to User</router-link> 
方式2
<router-link :to="{name:'user',params:{id:369}}">Go to User</router-link>

1.3 js mode – router.push

this.$router.push({
    
    name:'user',params:{
    
    id:1234}})

Two, named view

2.1 Create 2 new views

ShowMain.vue

<template>
    <h2>showMain</h2>
</template>

ShowSide.vue

<template>
    <h2>showSide</h2>
</template>

2.2 Configure router index.js

Where component is modified to components

const routes = [
    {
    
     
        path: '/', 
        components: {
    
    
            default:Home,
            ShowMain,
            ShowSide,
        } 
    },
 ]

2.3 Configure App.vue

router-view name='Specify the rendering location'

  <router-view></router-view>
  <router-view name="ShowMain"></router-view>
  <router-view name="ShowSide"></router-view>

insert image description here

Guess you like

Origin blog.csdn.net/Linlietao0587/article/details/128379690