1. VueRouter1. Description It feels natural to create single-page applications with Vue.js + Vue Router: with 2. Rendering of selected route:(1) router-link-exact-active class When routing to a certain place, the class name is added to the corresponding routing tag. (2) router-link-active class In routing, the path setting of the child route (for example: http://localhost/home) includes the path setting of the parent route (for example: http://localhost/). Then when the child route is clicked, when 3. Basic working principle Introduce router-link in the html part of 2. Actual Combat1. Create a vue project with router2. Open the src/router/index.js file in the project You can see that the project has automatically generated two routes, one is the Open 3. Open the project in the browser You can see two route navigations: 4. Create a new routeWrite a route navigation similar to Taobao, including four parts: home page, message, shopping cart and me. Create four new vue files, corresponding to four routes. Configure the routing index.js file import Vue from 'vue' import VueRouter from 'vue-router' import Home from '../views/Home.vue' Vue.use(VueRouter) const routes = [ { path: '/', name: 'Home', component: Home }, { path: '/message', name: 'Message', component: () => import(/* webpackChunkName: "about" */ '../views/Message.vue') }, { path: '/goodcar', name: 'GoodCar', component: () => import(/* webpackChunkName: "about" */ '../views/GoodCar.vue') }, { path: '/me', name: 'Me', component: () => import(/* webpackChunkName: "about" */ '../views/Me.vue') } ] const router = new VueRouter({ routes }) export default router Configure the navigation bar in App.vue <template> <div id="app"> <div id="nav"> <router-link to="/">Home</router-link> <router-link to="/message">message</router-link> <router-link to="/goodcar">Shopping Cart</router-link> <router-link to="/me">My</router-link> </div> <router-view/> </div> </template> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; } #nav { padding: 30px; margin: 0 auto; width: 30%; display: flex; justify-content: space-around; } #nav a { font-weight: bold; color: #2c3e50; text-decoration: none; } #nav a.router-link-exact-active { color: #42b983; } </style> result: So we understand the basic concept of routing and its configuration and its functions. This is the end of this article about Vue Learning - VueRouter Routing Basics. For more relevant VueRouter Routing Basics content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Implementation of comparison, sorting and other operations on varchar type dates in MySQL
>>: Introduction to Apache deployment of https in cryptography
There is a project developed on Mac, and the pack...
1. Two types of DMA mapping 1.1. Consistent DMA m...
HTML 4 HTML (not XHTML), MIME type is text/html, ...
1. Setting up nginx virtual host With virtual hos...
See the effect first Implementation Code <div ...
Xiaobai records the installation of vmtools: 1. S...
Table of contents MySQL result sorting - Aggregat...
Friends who have some basic knowledge of SQL must...
The reason is that this type of web page originate...
describe: fuser can show which program is current...
To summarize: Readonly is only valid for input (te...
Abstract: This article will demonstrate how to se...
<div class="box"> <img /> &...
Copy code The code is as follows: <a href=# ti...
This article shares the specific code for JavaScr...