1.App.vue 中寫
<template>
????<div?id="app">
????????<keep-alive>
????????????<router-view?v-if="$route.meta.keepAlive"?class="router-view">
????????????</router-view>
????????</keep-alive>
????????<router-view
????????????v-if="!$route.meta.keepAlive"
????????????class="router-view"
????????></router-view>
????</div>
</template>
2. 在router中寫??
{
????????path:?'/formal',
????????name:?'Formal',
????????component:?()?=>
????????????import(
????????????????/*?webpackChunkName:?'authentication'?*/?'../views/authentication/formal.vue'
????????????),
????????meta:?{? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//通過該值判斷頁面是否緩存
????????????keepAlive:?true,? ??
????????????isBack:?false
????????}
????},
3.? 在對應的頁面中監(jiān)聽路由 判斷頁面是從哪一個頁面跳轉(zhuǎn)至該頁面? (以下watch為ts寫法)
?@Watch('$route')
????onChangeValue(to:?any,?from:?any)?{
????????if?(from.path?===?'/upload')?{
????????????this.$route.meta.isBack?=?true;
????????????this.routerState?=?true;? ? //后面通過判斷該值決定是否清空內(nèi)容
????????}?else?{
????????????this.$route.meta.isBack?=?false;
????????????this.routerState?=?false;
????????}
????}