Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
b8846547
Commit
b8846547
authored
Dec 05, 2020
by
vben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix keepAlive not work
parent
4cca0071
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
14 additions
and
15 deletions
+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
No files found.
src/layouts/page/index.tsx
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment