使用多级路由的时候,router的index.js文件应该写成下面这种形式,不要想当然,注意path是多级的;而且children的内容是和router-view标签的个数对应的在第几层router-view 标签下,就是第几个children;
routes: [ { path: '/wzsb', name: 'wzsb', component: wzsb, children:[ {path:'/wzsb/kzsb', name:'kzsb', component:kzsb, children:[ {path:'/wzsb/kzsb/bgsb', name:'bgsb', component:bgsb} ]} ] }, ]
this.$route和this.$router的区别要搞清楚; this.$router是一个全局的vuerouter实例,如果想控制路由的跳转,就需要操作this.$router,使用this.$router.push()或者this.$router.replace()来跳转。
this.$route是当前路由跳转对象,通过它可以获取到当前路由的信息,比如this.$route.path就可以获取到当前路由的路径,但是不可以通过它操作路由的跳转。