//default-active设置当前激活的菜单。设置router使用 vue-router 的模式,启用该模式会在激活导航时以 index 作为 path 进行路由跳转
//index设置的值为path
{{menu.name}}
{{menu.name}}
{{item.name}}
//系统的菜单数据,渲染页面显示,灵活增删菜单
//route作为路径设置,name作为菜单名称显示,children作为是否有子菜单的判断。
data() {
return {
menus: [
{ route: '/', name: '首页' , children:false},
{ route: '/user', name: '用户管理' , children:false},
{ route: '/psd', name: '密码管理' , children:false},
{ route: '/salary', name: '工资管理' , children:false},
{ route: '/attendence', name: '考勤管理' , children:false},
{ route: '/perform', name: '绩效考核', children: [{ route: '/month', name: '月度绩效' }, { route: '/year', name: '年度绩效' }] },
{ route: '/admin', name: '系统管理' , children:false},
{ route: '/feedback', name: '意见反馈' , children:false}
]
}
},
路由应该与上面组件中显示的对应,否则不会跳转。
const router = new VueRouter({
routes: [
{
path: '/',
name: '首页',
component: main,
children: [
{
path: '/user',
name: '用户管理',
component: ElementTable,
},
{
path: '/userInfo/:id',
name: '用户详情页',
component: DetailInfo
},
{
path: '/psd',
name: '密码管理',
component: Template
},
{
path: '/salary',
name: '工资管理',
component: Template
},
{
path: '/attendence',
name: '考勤管理',
component: Template
},
{
path: '/perform',
name: '绩效考核',
component: Template,
children:[
{
path: '/month',
name: '月度绩效',
component: Monthform
},
{
path:'/year',
name: '年度绩效',
component: Theform
}
]
},
{
path: '/admin',
name: '系统管理',
component: Template
},
{
path: '/feedback',
name: '意见反馈',
component: Template
}
]
},
{
path: '*',
redirect: '/'
}
]
});
以上实现点击菜单项页面跳转到对应的路由页面。
回到顶部
路由跳转显示tab页面(main框架组件)
在框架组件中,采用watch监听页面路由改变(即点击菜单操作),新增路由添加tab页,点击已打开的路由则跳转到相应的tab页。
watch: {
'$route'(to) {
let flag = false;//判断是否页面中是否已经存在该路由下的tab页
//options记录当前页面中已存在的tab页
for (let option of this.options) {
//用名称匹配,如果存在即将对应的tab页设置为active显示桌面前端
if (option.name === to.name) {
flag = true;
this.$store.commit('set_active_index', '/' + to.path.split('/')[1]);
break;
}
}
//如果不存在,则新增tab页,再将新增的tab页设置为active显示在桌面前端
if (!flag) {
this.$store.commit('add_tabs', { route: '/' + to.path.split('/')[1], name: to.name });
this.$store.commit('set_active_index', '/' + to.path.split('/')[1]);
}
}
}
来看一下框架组件的html,将菜单组件app-nav引入,主界面为tab栏。
使用elementUI的tab组件,绑定activeIndex为激活tab页显示在桌面前端,利用for循环options显示所有已打开的tab页。
后台管理系统
