[学习记录]vue-router初步

vue-router起到了很重要的组件调度功能,这里只简单介绍下基本功能,以后有时间会把整个文档梳理一遍

 

 

最简单的路由就是在html中嵌入如下标签

<router-link to="/whereyouwanttogo">gogogo</router-link>

被路由的组件将出现在router-view标签中

<router-view></router-view>

 

然后再main.js中要加入router

import router from './router'

new Vue(
{
...
router,
...

}
)

在router文件夹中新建index.js

导入所有的组件,并且给定路由,下图为例

Vue.use(Router)

export default new Router({
  routes: [
    { path: '/', name: 'Home', component: Home },
    { path: '/about', name: 'About', component: About },
    { path: '/contact', name: 'Contact', component: Contact },
    { path: '/myvue', name: 'MyVue', component: MyVue }
  ]
})

 

posted @ 2019-06-11 19:35  冷血无情康纳酱  阅读(168)  评论(0编辑  收藏  举报