vue2.0笔记

2017-06-23  本文已影响0人  一梦两三年丶

1.路由配置

不用router下的index.js文件,直接在main.js里定义,路由import进

import VueRouter from 'vue-router'

再用 Vue.use(VueRouter),之后把要路由的组件import进来,再按照路由模版来定义就可以了

2.重定向

(1)把path都写在new VueRouter里,最后用{ path:'/', redirect:'/goods'}重定向

const router=new VueRouter({

routes:[

{ path:'/goods', component:goods},

{ path:'/ratings', component:ratings},

{ path:'/seller', component:seller},

{ path:'/', redirect:'/goods'}

]

})

(2)正常写法,在最后用{path:'/',component:goods}重定向。两种方法但是不能混写,不然内容不显示

const routes=[

{ path:'/goods', component:goods},

{ path:'/ratings', component:ratings},

{ path:'/seller', component:seller},

{path:'/',component:goods}

]

上一篇 下一篇

猜你喜欢

热点阅读