问题:项目中由于地图因为路由跳转加载销毁多次,占用浏览器内存,导致很卡,因此用了keep-alive存在store中
<keep-alive include="bookLists,bookLists"> // 缓存bookLists bookLists
<router-view></router-view>
</keep-alive>
<keep-alive exclude="indexLists"> // 除了indexLists都缓存
<router-view></router-view>
</keep-alive>
将首次触发请求写在created
钩子函数中,就能实现缓存
生命周期:
activated:组件被激活时触发
deactivated: 组件被移除时触发