Commit 8f9c4f18 authored by dragondean@qq.com's avatar dragondean@qq.com

优化保活逻辑,升级vue版本到2.6.14

parent 8f5f4381
<template>
<section class="app-main">
<transition name="fade-transform" mode="out-in">
<keep-alive :include="cachedViews">
<keep-alive :include="cachedViews" :exclude="excludeViews">
<router-view :key="key" />
</keep-alive>
</transition>
......
......@@ -2,7 +2,11 @@ import router from '@/router'
const state = {
visitedViews: [],
cachedViews: []
cachedViews: [],
}
// 获取页面的缓存名称
const getViewName = (view) => {
return view.meta.componentPath.split('/').map(item => item.substring(0, 1).toUpperCase() + item.substring(1).toLowerCase()).join('')
}
const mutations = {
......@@ -16,7 +20,7 @@ const mutations = {
},
ADD_CACHED_VIEW: (state, view) => {
if (view.meta && view.meta.componentPath) {
let cacheName = view.meta.componentPath.split('/').map(item => item.substring(0, 1).toUpperCase() + item.substring(1).toLowerCase()).join('')
let cacheName = getViewName(view)
if (state.cachedViews.includes(cacheName)) return
state.cachedViews.push(cacheName)
}
......@@ -31,7 +35,9 @@ const mutations = {
}
},
DEL_CACHED_VIEW: (state, view) => {
const index = state.cachedViews.indexOf(view.name)
console.log('DEL_CACHED_VIEW', view)
const viewName = getViewName(view)
const index = state.cachedViews.indexOf(viewName)
index > -1 && state.cachedViews.splice(index, 1)
},
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment