页签切换,一级菜单也要选中,报错信息提示多个问题

This commit is contained in:
mabo
2021-07-23 11:46:01 +08:00
parent 66462b9085
commit ae329419a6
16 changed files with 59 additions and 34 deletions

View File

@@ -338,6 +338,18 @@ util.initRouter = function (vm) { // 初始化路由
if (!menuData) {
return;
}
// 格式化数据,设置 空children 为 null
for(let i =0;i<menuData.length;i++){
let t = menuData[i].children
for(let k = 0;k<t.length;k++){
let tt = t[k].children;
for(let z = 0;z<tt.length;z++){
tt[z].children = null
// 给所有三级路由添加字段显示一级菜单name方便点击页签时的选中筛选
tt[z].firstRouterName = menuData[i].name
}
}
}
util.initAllMenuData(constRoutes, menuData);
util.initRouterNode(otherRoutes, otherRouter);
// 添加所有主界面路由
@@ -451,6 +463,7 @@ util.initRouterNode = function (routers, data) { // data为所有子菜单数
meta.permTypes = menu.permTypes ? menu.permTypes : null;
meta.title = menu.title ? menu.title + " - lilishop商家后台" : null;
meta.url = menu.url ? menu.url : null;
meta.firstRouterName = item.firstRouterName
menu.meta = meta;
routers.push(menu);

View File

@@ -46,6 +46,17 @@ export default {
return this.$store.state.app.currNav;
}
},
watch: {
// 监听路由变化
$route: {
handler: function (val, oldVal) {
console.log(val);
if (val.meta.firstRouterName && val.meta.firstRouterName !== this.currNav) {
this.selectNav(val.meta.firstRouterName)
}
}
}
},
methods: {
changeMenu(name) { //二级路由点击
this.$router.push({
@@ -56,6 +67,9 @@ export default {
this.$store.commit("setCurrNav", name);
this.setStore("currNav", name);
util.initRouter(this);
this.$nextTick(()=>{
this.$refs.childrenMenu.updateActiveName()
})
},
}
};