keep-alive如何设置跳转指定页面缓存,其它页面不缓存?

现在时无论跳转哪个页面都会缓存

{
  path: '/statistics/customerAsset/index',
  component: () => import('../view/statistics/customerAsset/index.vue'),
  meta: {
    title: '客户资产统计',
    keepAlive: true
  }
},
<el-main>
    <keep-alive>
        <router-view v-if="$route.meta.keepAlive" />
    </keep-alive>    
    <router-view v-if="!$route.meta.keepAlive" />                    
</el-main>
阅读 2.2k
2 个回答

KeepAlive组件会以key值作为缓存Map的key

<router-view v-slot="{ Component }">
    <keep-alive>
      <component
        v-if="$route.meta.isKeepAlive"
        :is="Component"
        :key="$route.name"
      />
    </keep-alive>
    <component
      v-if="!$route.meta.isKeepAlive"
      :is="Component"
      :key="$route.name"
    />
</router-view>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题