使用sessionStorage记录当前选中项
1.把当前数据存入到SessionStorage 中
<el-menu-item
:index="'/'+subItem.path"
v-for="subItem in item.children"
:key="subItem.id"
// 点击触发函数将数据存入到SessionStorage中
@click="saveNavState('/'+subItem.path)">
//在methods中
saveNavState(activePath){
window.sessionStorage.setItem('activePath',activePath)
this.activePath = activePath
}
2.再刷新页面时吧SessionStorage数据取出
在created 中有两种方式取出数据
在sessionStorage中可以获取到,有点可以刷新页面也可以使用
this.activePath = window.sessionStorage.getItem(“activePath”);
通过hash值获取可以更精确的获取数据,因sessionStorage的存储方法不支持回退,建议两种方法结合使用
// this.activePath = window.location.hash.substring(1);