在子页面下导航菜单的路由高亮判断函数如下:
vuex中:
//state
const state = { nowMue: "/adminIndex",
}
//mutations
nowMueChange(state, nowMue) { state.nowMue = nowMue; },
路由监听函数由$store.state.nowMue进行控制
<el-menu router unique-opened :default-active="$store.state.nowMue" class="el-menu-vertical-demo" text-color="#000" @select="handleSelect" :collapse="$store.state.isCollapse" active-text-color="#000"> <el-menu-item index="/adminIndex">首页</el-menu-item> <el-submenu :index="index+''" v-for="(item,index) in menuList" :key="index" router> <template slot="title"> <i class="el-icon-location"></i> <span>{{item.title}}</span> </template> <el-menu-item-group> <el-menu-item :index="item.path" v-for="(item,index) in item.items" :key="index">{{item.title}}</el-menu-item> </el-menu-item-group> </el-submenu> </el-menu>
监听路由变化进行处理,避免刷新失效
watch: { $route(to, form) { let vm = this; let arr = "/" + to.path.split("/")[1]; this.activeLeftMenu = arr; this.$store.commit("nowMueChange", arr); }, },
点击时进行数据更新
handleSelect(key, keyPath) { let arr = "/" + key.split("/")[1]; this.activeLeftMenu = arr; this.$store.commit("nowMueChange", arr); },
路由的写法:(包含一级或者二级路由原来的名字,用于判断)
path: '/LoanManage/LoanManageDetail'
如果有什么问题和疑问请在下方留言,文章为原创,转载请注明!