原理:
1)使用:default-active='activePath '
绑定属性activePath
2)点击时,使用select
事件把当前path
放进sessionStorage
里,
3)刷新时,从sessionStorage
里再获取回来,赋值给activePath
<el-menu background-color="#222832" text-color="#fff" :router="true" :default-active='activePath ' @select="saveActivePath">
<sidebar-item :menuList="menuItems"></sidebar-item>
</el-menu>
data(){
return {
activePath:''
}
},
created(){
this.activePath = window.sessionStorage.getItem('activePath')
},
methods:{
saveActivePath(activePath,v){
console.log(activePath,v);
window.sessionStorage.setItem('activePath',activePath);
this.activePath = activePath;
}
}