Home >Web Front-end >JS Tutorial >Several steps to create routing in vue

Several steps to create routing in vue

一个新手
一个新手Original
2017-10-07 11:39:343310browse

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

2. Define the routing

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

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

const router = new VueRouter({
        routes: routes
})

4. Create a mounting root instance

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

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>

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!

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