需求:有个页面外嵌iframe页面,发现切换菜单(这个页面有缓存),但是依然会调接口刷新,不能被缓存,希望切换回来不刷新
解决:在切换不含iframe的使用keepAlive缓存组件,在含有iframe的界面时用引入这个页面,作为组件,通过v-show来控制显隐,防止页面被重新更新。(v-if会重建Dom)
<template>
<keep-alive :include="$store.state.navHistoryName">
<router-view class="index" v-if="!iframeShow"/>
</keep-alive>
<component :is="currentView" v-show="iframeShow"></component>
<template>
<script>
//带有iframe的页面
import report from "../statisticalManagement/report";
export default {
data() {
return {
currentView:'report'
}
},
computed: {
iframeShow(){
const {iframe = false} = this.$route.meta
return iframe
},
}
}
</script>