1.效果
2.目录结构
3.router目录下index.js
//该文件用于创建整个应用的路由器
import VueRouter from "vue-router";
//创建并暴露一个路由器
export default new VueRouter({
routes:[
{
path:'/',
redirect:"/personMain",
component:() =>import ("../page/person/person")
},
{
path:'/Regsiter',
name:'Regsiter',
component:() =>import ("../page/regsiter")
},
{
path:'/Login',
name:'Login',
component:() =>import ("../page/login")
},
{
path:'/personMain',
name:'Main',
component:() =>import ("../page/person/person"),
children:[
{
path:'my',
name:"my",
component:()=>import("../page/person/view/my")
},
{
path:'search',
name:"search",
component:()=>import("../page/person/view/search")
},
{
path:'issue',
name:"issue",
component:()=>import("../page/person/view/issue")
}
]
},
{
path:'/adminMain',
name:'Main',
component:() =>import ("../page/admin/admin"),
children:[
{
path:'/analysis',
name:"analysis",
component:()=>import("../page/admin/view/analysis")
},
{
path:'/control',
name:"control",
component:()=>import("../page/admin/view/control")
}
]
}
]
})
4.使用子路由
mounted() {
this.$router.push('/personMain/my')
},
methods: {
handleSelect(index) {
console.log(typeof index)
if(index=="1")
this.$router.push('/personMain/my')
else if(index=="2")
this.$router.push('/personMain/search')
else if(index=="3")
this.$router.push('/personMain/issue')
},