PanJiaChen / vue-element-admin

:tada: A magical vue admin https://panjiachen.github.io/vue-element-admin
MIT License
87.6k stars 30.43k forks source link

keep-alive的替换方案localStorge #3889

Open small-dots opened 2 years ago

small-dots commented 2 years ago

Question(提问)

Screenshot or Gif(截图或动态图)

image 正对这种方案 能给点思路吗

wanqianjin commented 2 years ago

对于多级路由嵌套使keep-alive失效的情况,在src下面的permission.js文件中加入下面代码: router.beforeResolve((to, from, next) => { if (to.matched && to.matched.length > 2) { to.matched.splice(1, to.matched.length - 2) } next() }) 这样做就相当于让matched匹配的路由始终都是2个,tags-view导航就能缓存所有打开的页面了。 这样做会影响到面包屑导航: 下面是给出一个解决方案 1.recursiveTreeByLastLevel方法: /**