Skip to content

Commit

Permalink
fix(store): 修复 keepAliveRemove 操作后不能恢复页面缓存的 bug 以及相关 demo 页面
Browse files Browse the repository at this point in the history
  • Loading branch information
FairyEver committed Apr 22, 2020
1 parent ab0baf3 commit d249c86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/store/modules/d2admin/modules/page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get } from 'lodash'
import { cloneDeep, uniq, get } from 'lodash'
import router from '@/router'
import setting from '@/setting.js'

Expand Down Expand Up @@ -160,9 +160,9 @@ export default {
* @class current
* @description 打开一个新的页面
* @param {Object} context
* @param {Object} payload 从路由钩子的 to 对象上获取 { name, params, query, fullPath } 路由信息
* @param {Object} payload 从路由钩子的 to 对象上获取 { name, params, query, fullPath, meta } 路由信息
*/
open ({ state, commit, dispatch }, { name, params, query, fullPath }) {
open ({ state, commit, dispatch }, { name, params, query, fullPath, meta }) {
return new Promise(async resolve => {
// 已经打开的页面
let opened = state.opened
Expand Down Expand Up @@ -194,6 +194,11 @@ export default {
})
}
}
// 如果这个页面需要缓存 将其添加到缓存设置
if (isKeepAlive({ meta })) {
commit('keepAlivePush', name)
}
// 设置当前的页面
commit('currentSet', fullPath)
// end
resolve()
Expand Down Expand Up @@ -390,9 +395,9 @@ export default {
* @param {String} name name
*/
keepAlivePush (state, name) {
const keep = [ ...state.keepAlive ]
const keep = cloneDeep(state.keepAlive)
keep.push(name)
state.keepAlive = keep
state.keepAlive = uniq(keep)
},
/**
* @description 清空页面缓存设置
Expand Down
2 changes: 1 addition & 1 deletion src/views/demo/playground/store/page/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default {
},
// 清空当前页缓存并刷新此页面
async handleCleanCacheAndRefreshCurrent () {
this.keepAliveRemove(this.$route.fullPath)
this.keepAliveRemove(this.$route.name)
await this.$nextTick()
this.$router.replace('/refresh')
},
Expand Down

0 comments on commit d249c86

Please sign in to comment.