Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
b8846547
提交
b8846547
authored
12月 05, 2020
作者:
vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix keepAlive not work
上级
4cca0071
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
14 行增加
和
15 行删除
+14
-15
index.tsx
src/layouts/page/index.tsx
+1
-1
useCache.ts
src/layouts/page/useCache.ts
+2
-1
index.ts
src/router/guard/index.ts
+2
-6
index.ts
src/router/index.ts
+3
-3
level.ts
src/router/routes/modules/demo/level.ts
+1
-0
tab.ts
src/store/modules/tab.ts
+5
-4
没有找到文件。
src/layouts/page/index.tsx
浏览文件 @
b8846547
...
@@ -45,7 +45,7 @@ export default defineComponent({
...
@@ -45,7 +45,7 @@ export default defineComponent({
const
renderComp
=
()
=>
<
Component
key=
{
route
.
fullPath
}
/>;
const
renderComp
=
()
=>
<
Component
key=
{
route
.
fullPath
}
/>;
const
PageContent
=
unref
(
openCache
)
?
(
const
PageContent
=
unref
(
openCache
)
?
(
<
KeepAlive
>
{
renderComp
()
}
</
KeepAlive
>
<
KeepAlive
include=
{
cacheTabs
}
>
{
renderComp
()
}
</
KeepAlive
>
)
:
(
)
:
(
renderComp
()
renderComp
()
);
);
...
...
src/layouts/page/useCache.ts
浏览文件 @
b8846547
...
@@ -35,17 +35,18 @@ export function useCache(isPage: boolean) {
...
@@ -35,17 +35,18 @@ export function useCache(isPage: boolean) {
// not parent layout
// not parent layout
return
cached
.
get
(
PAGE_LAYOUT_KEY
)
||
[];
return
cached
.
get
(
PAGE_LAYOUT_KEY
)
||
[];
}
}
const
cacheSet
=
new
Set
<
string
>
();
const
cacheSet
=
new
Set
<
string
>
();
cacheSet
.
add
(
unref
(
name
));
cacheSet
.
add
(
unref
(
name
));
const
list
=
cached
.
get
(
unref
(
name
));
const
list
=
cached
.
get
(
unref
(
name
));
if
(
!
list
)
{
if
(
!
list
)
{
return
Array
.
from
(
cacheSet
);
return
Array
.
from
(
cacheSet
);
}
}
list
.
forEach
((
item
)
=>
{
list
.
forEach
((
item
)
=>
{
cacheSet
.
add
(
item
);
cacheSet
.
add
(
item
);
});
});
return
Array
.
from
(
cacheSet
);
return
Array
.
from
(
cacheSet
);
});
});
return
{
getCaches
};
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'
;
import
{
Modal
,
notification
}
from
'ant-design-vue'
;
...
@@ -50,7 +50,7 @@ export function createGuard(router: Router) {
...
@@ -50,7 +50,7 @@ export function createGuard(router: Router) {
return
true
;
return
true
;
});
});
router
.
afterEach
((
to
,
from
,
failure
)
=>
{
router
.
afterEach
((
to
)
=>
{
// scroll top
// scroll top
isHash
((
to
as
RouteLocationNormalized
&
{
href
:
string
})?.
href
)
&&
body
.
scrollTo
(
0
,
0
);
isHash
((
to
as
RouteLocationNormalized
&
{
href
:
string
})?.
href
)
&&
body
.
scrollTo
(
0
,
0
);
...
@@ -60,10 +60,6 @@ export function createGuard(router: Router) {
...
@@ -60,10 +60,6 @@ export function createGuard(router: Router) {
// change html title
// change html title
to
.
name
!==
REDIRECT_NAME
&&
setTitle
(
t
(
to
.
meta
.
title
),
globSetting
.
title
);
to
.
name
!==
REDIRECT_NAME
&&
setTitle
(
t
(
to
.
meta
.
title
),
globSetting
.
title
);
if
(
isNavigationFailure
(
failure
))
{
console
.
error
(
'router navigation failed:'
,
failure
);
}
});
});
createPageLoadingGuard
(
router
);
createPageLoadingGuard
(
router
);
createProgressGuard
(
router
);
createProgressGuard
(
router
);
...
...
src/router/index.ts
浏览文件 @
b8846547
...
@@ -35,8 +35,8 @@ export function setupRouter(app: App<Element>) {
...
@@ -35,8 +35,8 @@ export function setupRouter(app: App<Element>) {
createGuard
(
router
);
createGuard
(
router
);
}
}
router
.
onError
((
error
)
=>
{
//
router.onError((error) => {
console
.
error
(
error
);
//
console.error(error);
});
//
});
export
default
router
;
export
default
router
;
src/router/routes/modules/demo/level.ts
浏览文件 @
b8846547
...
@@ -55,6 +55,7 @@ const permission: AppRouteModule = {
...
@@ -55,6 +55,7 @@ const permission: AppRouteModule = {
component
:
()
=>
import
(
'/@/views/demo/level/Menu2.vue'
),
component
:
()
=>
import
(
'/@/views/demo/level/Menu2.vue'
),
meta
:
{
meta
:
{
title
:
'Menu2'
,
title
:
'Menu2'
,
// ignoreKeepAlive: true,
},
},
},
},
],
],
...
...
src/store/modules/tab.ts
浏览文件 @
b8846547
...
@@ -97,11 +97,13 @@ class Tab extends VuexModule {
...
@@ -97,11 +97,13 @@ class Tab extends VuexModule {
const
pageCacheSet
=
new
Set
<
string
>
();
const
pageCacheSet
=
new
Set
<
string
>
();
this
.
tabsState
.
forEach
((
tab
)
=>
{
this
.
tabsState
.
forEach
((
tab
)
=>
{
const
item
=
getRoute
(
tab
);
const
item
=
getRoute
(
tab
);
const
needAuth
=
!
item
.
meta
.
ignoreAuth
;
const
needCache
=
!
item
.
meta
.
ignoreKeepAlive
;
if
(
!
needCache
)
return
;
if
(
item
.
meta
.
affix
)
{
if
(
item
.
meta
.
affix
)
{
const
name
=
item
.
name
as
string
;
const
name
=
item
.
name
as
string
;
pageCacheSet
.
add
(
name
);
pageCacheSet
.
add
(
name
);
}
else
if
(
item
.
matched
&&
need
Auth
)
{
}
else
if
(
item
.
matched
&&
need
Cache
)
{
const
matched
=
item
.
matched
;
const
matched
=
item
.
matched
;
const
len
=
matched
.
length
;
const
len
=
matched
.
length
;
...
@@ -115,7 +117,7 @@ class Tab extends VuexModule {
...
@@ -115,7 +117,7 @@ class Tab extends VuexModule {
}
}
if
(
i
<
len
-
1
)
{
if
(
i
<
len
-
1
)
{
const
{
meta
,
name
}
=
matched
[
i
+
1
];
const
{
meta
,
name
}
=
matched
[
i
+
1
];
if
(
meta
&&
(
meta
.
affix
||
need
Auth
))
{
if
(
meta
&&
(
meta
.
affix
||
need
Cache
))
{
const
mapList
=
cacheMap
.
get
(
key
)
||
[];
const
mapList
=
cacheMap
.
get
(
key
)
||
[];
if
(
!
mapList
.
includes
(
name
as
string
))
{
if
(
!
mapList
.
includes
(
name
as
string
))
{
mapList
.
push
(
name
as
string
);
mapList
.
push
(
name
as
string
);
...
@@ -210,7 +212,6 @@ class Tab extends VuexModule {
...
@@ -210,7 +212,6 @@ class Tab extends VuexModule {
@
Mutation
@
Mutation
commitRedoPage
()
{
commitRedoPage
()
{
const
route
=
router
.
currentRoute
.
value
;
const
route
=
router
.
currentRoute
.
value
;
for
(
const
[
key
,
value
]
of
this
.
cachedMapState
)
{
for
(
const
[
key
,
value
]
of
this
.
cachedMapState
)
{
const
index
=
value
.
findIndex
((
item
)
=>
item
===
(
route
.
name
as
string
));
const
index
=
value
.
findIndex
((
item
)
=>
item
===
(
route
.
name
as
string
));
if
(
index
===
-
1
)
{
if
(
index
===
-
1
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论