1. DescriptionVue Router is the official routing manager for Vue.js. It is deeply integrated with the core of Vue.js, making it easy to build single-page applications. Features included are:
2. Installation Test and learn based on the first vue-cli; First check whether vue-router exists in node modules npm install vue-router --save-dev If you use it in a modular project, you must explicitly install the routing function via Vue.use(): import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter); 3. Testing 1. Delete useless things first <template> <div> <h1>Contents Page</h1> </div> </template> <script> export default { name:"Content" } </script> Main.vue component <template> <div> <h1>Home</h1> </div> </template> <script> export default { name:"Main" } </script> 4. Install the router. In the src directory, create a new folder: router to store the router and configure the router index.js as follows import Vue from 'vue' //Import routing plugin import Router from 'vue-router' //Import the components defined above import Content from '../components/Content' import Main from '../components/Main' //Install routing Vue.use(Router); //Configure routing export default new Router({ routes:[ { //Route path path:'/content', //Route name name:'content', // Jump to component component:Content }, { //Route path path:'/main', //Route name name:'main', // Jump to component component:Main } ] }); 5. Configure routing in main.js import Vue from 'vue' import App from './App' //Import the routing configuration directory created above import router from './router' //Automatically scan the routing configuration inside //To turn off the prompt given in production mode Vue.config.productionTip = false; new Vue({ el:"#app", //Configure routing router, components:{App}, template:'<App/>' }); 6. Use routing in App.vue <template> <div id="app"> <!-- router-link: By default, it will be rendered as an <a> tag, and the to attribute is the specified link router-view: used to render the component matched by the route --> <router-link to="/main">Home</router-link> <router-link to="/content">content</router-link> <router-view></router-view> </div> </template> <script> export default{ name:'App' } </script> <style></style> The above is the detailed content of how to use Vue-router routing. For more information about the use of Vue-router routing, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: MySQL 5.7.18 installation and configuration method graphic tutorial (CentOS7)
>>: Tutorial on how to deploy LNMP and enable HTTPS service
1. Record several methods of centering the box: 1...
This is the installation tutorial of mysql5.7.18....
Publish Over SSH Plugin Usage Before using Publis...
In daily operation and maintenance work, nginx se...
Table of contents introduction Indexing principle...
closure service nginx stop systemctl stop nginx s...
Table of contents Jenkins installation Install Ch...
Recently, the client of a project insisted on hav...
This article example shares the specific code of ...
Startups often bring us surprises with their unco...
Preface At work, we often need to operate in a Li...
This article example shares the specific code of ...
For any DBMS, indexes are the most important fact...
When using Flex layout, you will find that when a...
This tutorial is only applicable to Windows syste...