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>


回答:

可以使用<keep-alive>的include或者exclude属性。前提是你有给路由组件设置name属性。
https://v2.cn.vuejs.org/v2/ap...


回答:

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>

以上是 keep-alive如何设置跳转指定页面缓存,其它页面不缓存? 的全部内容, 来源链接: utcz.com/p/933356.html

回到顶部