Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zuiqiangwanggong
vue-vben-admin
提交
b8846547
V
vue-vben-admin
项目概览
zuiqiangwanggong
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b8846547
编写于
12月 05, 2020
作者:
V
vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix keepAlive not work
上级
4cca0071
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
14 addition
and
15 deletion
+14
-15
src/layouts/page/index.tsx
src/layouts/page/index.tsx
+1
-1
src/layouts/page/useCache.ts
src/layouts/page/useCache.ts
+2
-1
src/router/guard/index.ts
src/router/guard/index.ts
+2
-6
src/router/index.ts
src/router/index.ts
+3
-3
src/router/routes/modules/demo/level.ts
src/router/routes/modules/demo/level.ts
+1
-0
src/store/modules/tab.ts
src/store/modules/tab.ts
+5
-4
未找到文件。
src/layouts/page/index.tsx
浏览文件 @
b8846547
...
...
@@ -45,7 +45,7 @@ export default defineComponent({
const
renderComp
=
()
=>
<
Component
key
=
{
route
.
fullPath
}
/>;
const
PageContent
=
unref
(
openCache
)
?
(
<
KeepAlive
>
{
renderComp
()
}
</
KeepAlive
>
<
KeepAlive
include
=
{
cacheTabs
}
>
{
renderComp
()
}
</
KeepAlive
>
)
:
(
renderComp
()
);
...
...
src/layouts/page/useCache.ts
浏览文件 @
b8846547
...
...
@@ -35,17 +35,18 @@ export function useCache(isPage: boolean) {
// not parent layout
return
cached
.
get
(
PAGE_LAYOUT_KEY
)
||
[];
}
const
cacheSet
=
new
Set
<
string
>
();
cacheSet
.
add
(
unref
(
name
));
const
list
=
cached
.
get
(
unref
(
name
));
if
(
!
list
)
{
return
Array
.
from
(
cacheSet
);
}
list
.
forEach
((
item
)
=>
{
cacheSet
.
add
(
item
);
});
return
Array
.
from
(
cacheSet
);
});
return
{
getCaches
};
...
...
src/router/guard/index.ts
浏览文件 @
b8846547
import
{
isNavigationFailure
,
RouteLocationNormalized
,
Router
}
from
'
vue-router
'
;
import
{
RouteLocationNormalized
,
Router
}
from
'
vue-router
'
;
import
{
Modal
,
notification
}
from
'
ant-design-vue
'
;
...
...
@@ -50,7 +50,7 @@ export function createGuard(router: Router) {
return
true
;
});
router
.
afterEach
((
to
,
from
,
failure
)
=>
{
router
.
afterEach
((
to
)
=>
{
// scroll top
isHash
((
to
as
RouteLocationNormalized
&
{
href
:
string
})?.
href
)
&&
body
.
scrollTo
(
0
,
0
);
...
...
@@ -60,10 +60,6 @@ export function createGuard(router: Router) {
// change html title
to
.
name
!==
REDIRECT_NAME
&&
setTitle
(
t
(
to
.
meta
.
title
),
globSetting
.
title
);
if
(
isNavigationFailure
(
failure
))
{
console
.
error
(
'
router navigation failed:
'
,
failure
);
}
});
createPageLoadingGuard
(
router
);
createProgressGuard
(
router
);
...
...
src/router/index.ts
浏览文件 @
b8846547
...
...
@@ -35,8 +35,8 @@ export function setupRouter(app: App<Element>) {
createGuard
(
router
);
}
router
.
onError
((
error
)
=>
{
console
.
error
(
error
);
});
//
router.onError((error) => {
//
console.error(error);
//
});
export
default
router
;
src/router/routes/modules/demo/level.ts
浏览文件 @
b8846547
...
...
@@ -55,6 +55,7 @@ const permission: AppRouteModule = {
component
:
()
=>
import
(
'
/@/views/demo/level/Menu2.vue
'
),
meta
:
{
title
:
'
Menu2
'
,
// ignoreKeepAlive: true,
},
},
],
...
...
src/store/modules/tab.ts
浏览文件 @
b8846547
...
...
@@ -97,11 +97,13 @@ class Tab extends VuexModule {
const
pageCacheSet
=
new
Set
<
string
>
();
this
.
tabsState
.
forEach
((
tab
)
=>
{
const
item
=
getRoute
(
tab
);
const
needAuth
=
!
item
.
meta
.
ignoreAuth
;
const
needCache
=
!
item
.
meta
.
ignoreKeepAlive
;
if
(
!
needCache
)
return
;
if
(
item
.
meta
.
affix
)
{
const
name
=
item
.
name
as
string
;
pageCacheSet
.
add
(
name
);
}
else
if
(
item
.
matched
&&
need
Auth
)
{
}
else
if
(
item
.
matched
&&
need
Cache
)
{
const
matched
=
item
.
matched
;
const
len
=
matched
.
length
;
...
...
@@ -115,7 +117,7 @@ class Tab extends VuexModule {
}
if
(
i
<
len
-
1
)
{
const
{
meta
,
name
}
=
matched
[
i
+
1
];
if
(
meta
&&
(
meta
.
affix
||
need
Auth
))
{
if
(
meta
&&
(
meta
.
affix
||
need
Cache
))
{
const
mapList
=
cacheMap
.
get
(
key
)
||
[];
if
(
!
mapList
.
includes
(
name
as
string
))
{
mapList
.
push
(
name
as
string
);
...
...
@@ -210,7 +212,6 @@ class Tab extends VuexModule {
@
Mutation
commitRedoPage
()
{
const
route
=
router
.
currentRoute
.
value
;
for
(
const
[
key
,
value
]
of
this
.
cachedMapState
)
{
const
index
=
value
.
findIndex
((
item
)
=>
item
===
(
route
.
name
as
string
));
if
(
index
===
-
1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录