1. 程式人生 > >vue開發:vue動態路由匹配

vue開發:vue動態路由匹配

<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>


<div id="app">
  <p>
    <router-link to="/user/foo">/user/foo</router-link>
    <router-link to="/user/bar">/user/bar</router-link>
  </p>
  <router-view></router-view>

</div>

const User = {
  template: `<div>User {{ $route.params.id }}</div>`
}


const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User }
  ]
})


const app = new Vue({ router }).$mount('#app')