introduce
InstallInstallation Commands npm install vue-router --save If you use it in a modular project, you must explicitly install the routing function via import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) Modular use When we used the scaffolding import Vue from "vue"; import VueRouter from "vue-router"; import Home from "../views/Home.vue"; // 1. When we use other plug-ins, we must use Vue.use to install the plug-in Vue.use(VueRouter); // 2. Define routes, each route should map to a component const routes = [ { path: "/", name: "Home", component: Home, }, { path: "/about", name: "About", component: About }, ]; // 3. Create a router instance const router = new VueRouter({ //Configure the application relationship between routes and components routes, // (abbreviation) equivalent to routes: routes }); // 4. Export the router object, and then reference export default router in main.js; This file is specifically for configuring routing. Finally, after exporting import Vue from "vue"; import App from "./App.vue"; import router from "./router"; Vue.config.productionTip = false; new Vue({ router, // Add the router object to the vue instance, and you can use routing render: (h) => h(App), }).$mount("#app"); Our two component codes // About.vue <template> <div class="about"> <h1>About</h1> </div> </template> <script> export default { name: "About" } </script> <style scoped> </style> // Home.vue <template> <div class="home"> <h1>Home</h1> </div> </template> <script> export default { name: "Home", }; </script> <style scoped> </style> Finally, we write the following code in template> <div id="app"> <router-link to="/">Home</router-link> <router-link to="/about">About</router-link> <router-view></router-view> </div> </template> <style lang="scss"> </style> Use HTML5 history mode But when we start the program and access the page, This is because const router = new VueRouter({ mode: 'history', routes: [...] }) We just need to add Note: Therefore, you need to add a candidate resource on the server to cover all situations: if This is the end of this article about the installation and configuration of vue-route routing management. For more relevant vue route installation and configuration content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed example of MySQL (5.6 and below) parsing JSON
After going through a lot of hardships, I searched...
Table of contents 1. Learning Objectives 1.1. Mas...
Table of contents What happened? When to use Cont...
Use wget command to download the entire subdirect...
Table of contents Introduction Public code (backe...
Table of contents Preface Method 1: High contrast...
Generic load/write methods Manually specify optio...
Related knowledge points Passing values from pa...
1 Background Recently, I have been studying how t...
Installation suggestion : Try not to use .exe for...
In the previous article, I introduced the detaile...
<br />In the previous article, I introduced ...
This article shares the specific code for JavaScr...
The following demonstration is based on MySQL ver...
When the DataSource property of a DataGrid control...