启用keepalive的页面缓存功能

dev
RogerWork 4 months ago
parent 1a2ba162cf
commit 56f661fe4d
  1. 17
      src/components/ec_api/BasicConfig.vue
  2. 10
      src/layout/index.vue
  3. 2
      src/request/index.js
  4. 19
      src/router/index.js

@ -192,19 +192,6 @@ function store_data() {
store.commit('ecApiModule/change_ec_select_api', SelectApi.value) store.commit('ecApiModule/change_ec_select_api', SelectApi.value)
} }
//
function restore_data() {
SelectEnv.value = store.state.ecApiModule.ec_api_data.env
SelectCinema.value = store.state.ecApiModule.ec_api_data.cinema
SelectType.value = store.state.ecApiModule.ec_api_data.type
SelectChannel.value = store.state.ecApiModule.ec_api_data.channel
SelectApiGroup.value = store.state.ecApiModule.ec_api_data.api_group
SelectApiId.value = store.state.ecApiModule.ec_api_data.select_api_id
CinemaByEnv.value = store.state.ecApiModule.ec_api_data.cinema_env
ChannelByType.value = store.state.ecApiModule.ec_api_data.channel_type
SelectApi.value = store.state.ecApiModule.ec_api_data.select_api ? store.state.ecApiModule.ec_api_data.select_api : []
}
onMounted(() => { onMounted(() => {
console.log('onMounted BasicConfig') console.log('onMounted BasicConfig')
SelectType.value = store.state.ecApiModule.ec_api_data.type SelectType.value = store.state.ecApiModule.ec_api_data.type
@ -220,10 +207,6 @@ onMounted(() => {
get_api_by_type(SelectType.value) get_api_by_type(SelectType.value)
// //
get_api_params_by_type(SelectType.value) get_api_params_by_type(SelectType.value)
//
restore_data()
console.log('BasicConfig onMounted store.state.ecApiModule.ec_api_data', store.state.ecApiModule.ec_api_data)
}) })

@ -3,6 +3,9 @@
import Index from "@/views/update/index.vue"; import Index from "@/views/update/index.vue";
import PageHeader from "@/layout/components/PageHeader.vue"; import PageHeader from "@/layout/components/PageHeader.vue";
import PageAside from "@/layout/components/PageAside.vue"; import PageAside from "@/layout/components/PageAside.vue";
import {useRoute} from 'vue-router'
const route = useRoute()
</script> </script>
<template> <template>
@ -16,7 +19,12 @@ import PageAside from "@/layout/components/PageAside.vue";
<!-- <PageHeader/>--> <!-- <PageHeader/>-->
<!-- </el-header>--> <!-- </el-header>-->
<el-main> <el-main>
<router-view/> <router-view v-slot="{Component}">
<keep-alive>
<component :is="Component" v-if="route.meta.keepAlive"/>
</keep-alive>
<component :is="Component" v-if="!route.meta.keepAlive"/>
</router-view>
</el-main> </el-main>
</el-container> </el-container>
</el-container> </el-container>

@ -5,11 +5,9 @@ import config from "@/request/config.js";
// import router from "@/router"; // import router from "@/router";
function request(options) { function request(options) {
console.log(options)
const instance = axios.create({...config}) const instance = axios.create({...config})
options = {...options, instance} // 使用创建的实例 options = {...options, instance} // 使用创建的实例
console.log(options)
// 请求拦截器 // 请求拦截器
instance.interceptors.request.use( instance.interceptors.request.use(
config => { config => {

@ -6,26 +6,41 @@ const routes = [
path: '/', path: '/',
name: 'Home', name: 'Home',
component: Layout, component: Layout,
meta:{
keepAlive: true,
},
children: [ children: [
{ {
path: '/', path: '/',
name: 'hello', name: 'hello',
component: () => import('@/components/HelloWorld.vue') component: () => import('@/components/HelloWorld.vue'),
meta:{
keepAlive: true,
}
}, },
{ {
path: 'update', path: 'update',
name: 'Update', name: 'Update',
component: () => import('@/views/update/index.vue') component: () => import('@/views/update/index.vue'),
meta:{
keepAlive: false,
}
}, },
{ {
path: 'mock', path: 'mock',
name: 'Mock', name: 'Mock',
component: () => import('@/views/mock/index.vue'), component: () => import('@/views/mock/index.vue'),
meta:{
keepAlive: false,
}
}, },
{ {
path: 'ec_api', path: 'ec_api',
name: 'EcApi', name: 'EcApi',
component: () => import('@/views/ec_api/index.vue'), component: () => import('@/views/ec_api/index.vue'),
meta:{
keepAlive: true,
}
} }
] ]
} }

Loading…
Cancel
Save