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

How vue.js refers to vue router

coldplay.xixi
coldplay.xixiOriginal
2020-11-12 16:50:132294browse

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

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>

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;);

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!

Statement:
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