美文网首页
Vue 如何返回页面时不重新发接口

Vue 如何返回页面时不重新发接口

作者: 三浦蒼介 | 来源:发表于2019-12-20 19:50 被阅读0次

1 app.vue 里面 注意route.meta.keepAlive
<template>
<div id="app">
<transition :name="transitionName">
<router-view class="child-view" v-if="!route.meta.keepAlive" v-wechat-title='route.meta.title'></router-view>
</transition>
<transition :name="transitionName">
<keep-alive>
<router-view class="child-view" v-if="route.meta.keepAlive" v-wechat-title='route.meta.title'></router-view>
</keep-alive>
</transition>
<loading></loading>
</div>
</template>

2 index.js里面,在不想刷新的地方 添加keepAlive:true

3 写方法
就是A跳B,如果不想让A重新发接口,就在B页面加,然后B返回A的时候,A就不发接口了
beforeRouteLeave(to, from, next) {
// 设置下一个路由的 meta
to.meta.keepAlive = true; // 让 A 缓存,即不刷新
next();
},

相关文章