vue route built-in module described in detail router-view (map with the truth)

Introduction

  • When you address compliance with the requirements of my route, will route your interface component presented, and the interface is really inside App.vue

  • When you open App.vue will be found inside these two components
  • These two are two built-in component vue vue to provide you with

Here Insert Picture Description


Features

router-link it possible to jump between routing
router-view when you route when the address matches the access path , will be specified components replace the router-view

router-view function codes embodied Introduction

Step 1: Create your component (corresponding page)

  • This file can be placed in any place, but I strongly recommend that you build a folder on the inside
  • This is my creation component (page)

Here Insert Picture Description


Step Two: written into the corresponding address in the route

  • For example, I want it contents of the address bar is http://127.0.0.1/my when I enter the specified page
  • As for why I was 127.0.0.1 address change article
  {
    path:'/my',
    component:()=>import('../components/my.vue')
  },
  • It is written here routing components ⬇⬇
    Here Insert Picture Description

The third step: Enter the appropriate address in the browser

  • vue update is hot, there is no need to refresh the page can use
    Here Insert Picture Description

result:
Here Insert Picture Description

summary:

  1. We can see the results of our content page is displayed in the assembly

  2. And only one

  3. Are you curious about how he got there rendered?

  4. You say I only wrote a div, wrong , it is because the components can have only one root element

  5. Then you think about it, we mentioned at the beginning of router-view

    router-view when your route is complying with the access path address will be specified component to replace the router-view
    Here Insert Picture Description
    Yes, that is it becomes your components


Distrust?

  • That we write a few router-view try
    Here Insert Picture Description
    to see, I wrote a five breath, then let's look at how a page is displayed
    Dangdang when ~ ~ ~
    Here Insert Picture Description
Published 63 original articles · won praise 6 · views 1210

Guess you like

Origin blog.csdn.net/qq_44163269/article/details/105185163