13用户列表-在sessionStorage 中保存激活的菜单
菜单属性default-active
- 关键代码块
<!--菜单属性-->
<el-menu :default-active="activePath">
<!--default-active默认的激活菜单-->
<!--二级菜单添加click事件saveNavState-->
<el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id"
@click="saveNavState('/' + subItem.path)">
<template slot="title">
<!-- 图标 ,将二级图标设置成menu-->
<i class="el-icon-menu"></i>
<!-- 文本 -->
<span>{{subItem.authName}}</span>
</template>
</el-menu-item>
//初始化activePath
data() {
return{
//被激活的连接地址
activePath: '',
}
},
// 默认加载sessionStorage中的activePath
created() {
this.getMenuList();
//获取默认的激活连接
this.activePath = window.sessionStorage.getItem('activePath')
},
methods: {
//保存连接的激活状态
saveNavState(activePath) {
window.sessionStorage.setItem('activePath', activePath);
//切换后要记得保存状态值
this.activePath = activePath
}
}
}