Home > Web Front-end > Vue.js > How vue.js refers to vue router

How vue.js refers to vue router

coldplay.xixi
Release: 2020-11-12 16:50:13
Original
2317 people have browsed it

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].

How vue.js refers to vue router

【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
Copy after login

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-linkdirective, such as :

<a v-link="{path: &#39;/view-a&#39;}">Go to view-a</a>
Copy after login

ps: v-link also supports activeClass for specifying the css style when the link is active. replaceWhen 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({
  &#39;/view-a&#39;: {
    component: ViewA
  },
  &#39;/view-b&#39;: {
    component: ViewB
  }
});
router.start(App, &#39;#app&#39;);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template