Home > Web Front-end > JS Tutorial > body text

Several steps to create routing in vue

一个新手
Release: 2017-10-07 11:39:34
Original
3282 people have browsed it

Several steps to create routing in vue;
Step one: Define the components that require routing.
Step 2: Define routing.
Step 3: Create a routing instance and pass in the configuration of the defined route
Step 4: Create a root instance to mount the route.
1. Define the routing component

const Foo : {template: &#39;<p> this is foo </p>
const Bar : {template: &#39;<p> this is bar </p>
.....
Copy after login

2. Define the routing

const routes: [
{path: &#39;/foo&#39;, component: Foo},
{path: &#39;/bar&#39;, component: Bar}
]
Copy after login

3. Create a routing instance and pass in the configuration for defining the routing

const router = new VueRouter({
        routes: routes
})
Copy after login

4. Create a mounting root instance

const app = new Vue({
router: router
}).$mount(&#39;#app&#39;)
Copy after login

HTML

<!--外部链接--><script src="https://unpkg.com/vue/dist/vue.js"></script><script src="https://unpkg.com/vue-router/dist/vue-router.js"></script><p id="app">
  <h1>Hello</h1>
  <p>
    <router-link to="/foo">Go to Foo</router-link>
    <router-link to="/bar">Go to Bar</router-link>
  </p>
  <router-view></router-view></p>
Copy after login

The above is the detailed content of Several steps to create routing in vue. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!