vue路由使用keep-alive

keep-alive:保持组件状态,不被频繁销毁创建销毁

使用:

<keep-alive><router-view></router-view></keep-alive>


只有在使用 keep-alive 时activated(活跃时运行)、deactivated(失去焦点时运行)这两个函数才有用。

当有组件嵌套,想保持子组件的状态和地址时可使用   组件内的守卫:deforeRouterLeave 进行地址的变化记录更改,使下一次再次点击时回到最后显示的地方

beforeRouteLeave(to,from,next){
console.log(this.$route.path);
this.patch = this.$route.path
next()
}
原文地址:https://www.cnblogs.com/lucky-jun/p/14190669.html