只给部分组件加上<keep-alive>啊,在app.vue里这样
<!-- 这里是需要keepalive的 --> <keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> </keep-alive> <!-- 这里不会被keepalive --> <router-view v-if="!$route.meta.keepAlive"></router-view>
然后在设置路由信息的时候这样
{ path: ‘‘, name: ‘‘, component: , meta: {keepAlive: true} // 这个是需要keepalive的 }, { path: ‘/home‘, name: ‘home‘, component: homepage, meta: {keepAlive: false} // 这是不会被keepalive的 }
时间: 2024-10-06 12:45:10