Vue.js路由:个人理解为单页面显示不同组件
//cdn<script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue-router/2.7.0/vue-router.min.js"></script>
<div id="app">
<router-link to="/foo">go to Foo</router-link> //映射为a标签,to为href
<router-link to="/bar">go to bar</router-link>
<router-view></router-view> //显示路由映射的组件
</div>
1.定义组件
const Foo = { template: "<h1>this is foo<h1>"}
const Bar = { template: "<h2>this is bar</h2>"}
const routes=[
{path:'/foo',component:Foo},
{path:'/bar',component:Bar}
]
const router = new VueRouter({
routes: routs //简写可去掉routes:
})
const app=new Vue({
router
}).$mount("#app") //挂载方法
</script>