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>
推荐问题