作用

让不展示的路由组件保持挂载,不被销毁

具体编码

在需要缓存的路由组件上级组件中编写如下代码

<keep-alive include="name1,name2,..."> <router-view></router-view></keep-alive><keep-alive :include="['name1','name2',...]"> <router-view></router-view></keep-alive>