vue动态改变keepAlive状态

Vue动态改变keepAlive缓存(推荐)https://blog.csdn.net/weixin_44489221/article/details/103917015
结论:通过的include属性和vuex设置

最好使用如下方式:

<keep-alive :include="cached">
   <router-view />
</keep-alive>

动态改变keepAlive时,不建议使用如下方式:

// 这种方式会引起异常情况
// 和beforeRouteLeave方法配合动态改变keepAlive,第一次执行正常,第二次及之后组件会一直是keepAlive=false
<keep-alive>
  <router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
原文地址:https://www.cnblogs.com/myc-xiaochaochao/p/13900217.html