Vue.js refers to the vue router method: first install the npm package, the code is [npm install vue-router --save]; then use the [v-link] [directive].
【Recommended related articles: vue.js】
vue.js refers to the vue router method:
Installation
Based on tradition, I prefer Install it as an npm package.
npm install vue-router --save
Of course, the official uses a variety of methods for installation, including bower, cdn, etc.
Basic usage
When used in HTML documents, just use the v-link
directive
, such as :
<a v-link="{path: '/view-a'}">Go to view-a</a>
ps: v-link
also supports activeClass for specifying the css style when the link is active. replace
When the attribute is true, the link will not leave a history record when jumping.
To use it in ES5, you need to create a router instance first, and then pass in the configuration parameters, such as:
var router = new VueRouter(); router.map({ '/view-a': { component: ViewA }, '/view-b': { component: ViewB } }); router.start(App, '#app');
The router rules defined above are mapped to a component, and finally When starting the application, mount it to the #app element.
Related free learning recommendations: JavaScript (video)
The above is the detailed content of How vue.js refers to vue router. For more information, please follow other related articles on the PHP Chinese website!