基本路由
启动和运行 vue-router 的最简单方法是使用通过 CDN 提供的版本。
HTML:
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<div id="router-example">
<router-link to="/foo">Link to Foo route</router-link>
<router-view></router-view>
</div>
JavaScript(ES2015)
:
const Foo = { template: <div>This is the component for the Foo route</div> }
const router = new VueRouter({
routes: [
{ path: '/foo', component: Foo}
]
})
const routerExample = new Vue({
router
}).$mount('#router-example')