How to use Vue-Router to switch between multiple pages?

Use Vue-Router to switch between multiple pages

1. Download Vue-Router

Insert picture description here

2. Create a dedicated folder, create js in the folder for configuration

Insert picture description here
The config configuration mode URL display method is the normal route
routes. Configure the default address of the component corresponding to each address.'/' Display the homepage component.
If multiple pages need to use the same component but the request data is different, you can add it after it: id is not necessarily You must take the id, you can define your own
'*' to indicate that all the above addresses are not matched, then the 404 error page
name is executed to better and more accurately jump to the desired page. If it is only the path, the path will not be found if you change the path Page, after having a name, no matter how to modify the path address, it will jump to the corresponding address of the name.

Insert picture description here

index Import vue-router vue config
Use vue-router to
pass config into configuration vue-router Return to configured router

Insert picture description here

Use vue-router

Import router Add router to the vue instance object and
Insert picture description here
use the router-view tag in the app.vue component. The
router-view tag will selectively display the corresponding component according to the change of the page address, so as to realize multi-page switching in a single page.

Insert picture description here
The router-link tag is equivalent to the a tag, but using router-link can prevent page refresh.
Use to with the corresponding address to configure the corresponding name of the jump in to.
Multiple pages with the same name can be matched in detail. Configure the id of the corresponding page and the id of the request array Whether it is consistent to switch

Insert picture description here

End

index
Insert picture description here

news
Insert picture description here
news
Insert picture description here
login
Insert picture description here
is successfully executed in this way. Use vue-router to switch multiple pages~
Like it, Mina 0.0

Guess you like

Origin blog.csdn.net/kzj0916/article/details/107951779