美文网首页
vue2.0笔记

vue2.0笔记

作者: 一梦两三年丶 | 来源:发表于2017-06-23 18:26 被阅读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}

]

相关文章

网友评论

      本文标题:vue2.0笔记

      本文链接:https://www.haomeiwen.com/subject/mjgccxtx.html