Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
lxyl-vue
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
李苏
lxyl-vue
Commits
3bf0fefb
Commit
3bf0fefb
authored
Jun 05, 2024
by
李苏
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vuex 监听异步
parent
4799ef94
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
10 deletions
+69
-10
AppMain.vue
src/layout/components/AppMain.vue
+60
-8
index.vue
src/layout/components/TagsView/index.vue
+2
-0
tagsView.js
src/store/modules/tagsView.js
+7
-2
No files found.
src/layout/components/AppMain.vue
View file @
3bf0fefb
<
template
>
<section
class=
"app-main"
>
<transition
name=
"fade-transform"
mode=
"out-in"
>
<keep-alive
v-if=
"cachedViews.includes(key)"
>
<router-view
:key=
"key"
/>
<keep-alive
>
<template
v-show=
"isCache"
>
<router-view
/>
</
template
>
</keep-alive>
<router-view
v-else
:key=
"key
"
/>
</transition>
<router-view
v-if=
"!isCache
"
/>
</section>
</template>
...
...
@@ -16,9 +18,59 @@ export default {
cachedViews
()
{
return
this
.
$store
.
state
.
tagsView
.
cachedViews
},
key
()
{
console
.
log
(
this
.
$route
.
name
)
return
this
.
$route
.
name
},
watch
:{
cachedViews
(
val
){
this
.
JSONcachedViews
=
JSON
.
stringify
(
val
)
},
JSONcachedViews
(
nv
,
ov
){
let
nvobj
=
JSON
.
parse
(
nv
)
let
ovobj
=
JSON
.
parse
(
ov
)
this
.
oldCachedViews
=
ovobj
if
(
nvobj
.
length
>
ovobj
.
length
){
this
.
addBz
=
true
}
else
{
this
.
addBz
=
false
}
},
$route
(
val
){
// console.log(this.isCache)
// debugger
this
.
isCache
=
true
this
.
key
=
val
.
name
if
(
this
.
addBz
){
if
(
this
.
oldCachedViews
.
includes
(
val
.
name
)){
this
.
isCache
=
true
}
else
{
this
.
isCache
=
false
}
// if(this.oldCachedViews.includes(val.name)){
// this.isCache=true
// }else{
// this.isCache=false
// }
this
.
addBz
=
false
}
else
{
// this.isCache=true
if
(
this
.
cachedViews
.
includes
(
val
.
name
)){
console
.
log
(
'包含,进入缓存'
)
this
.
isCache
=
true
}
else
{
console
.
log
(
'不包含,不进入缓存'
)
this
.
isCache
=
false
}
// this.isCache=this.cachedViews.includes(val.name)
}
}
},
data
(){
return
{
isCache
:
true
,
JSONcachedViews
:
''
,
addBz
:
false
,
key
:
null
,
oldCachedViews
:[]
}
}
}
...
...
src/layout/components/TagsView/index.vue
View file @
3bf0fefb
...
...
@@ -59,6 +59,8 @@
},
watch
:
{
$route
()
{
this
.
$store
.
commit
(
'tagsView/setKey'
,
this
.
$route
.
name
)
this
.
addTags
()
this
.
moveToCurrentTag
()
},
...
...
src/store/modules/tagsView.js
View file @
3bf0fefb
const
state
=
{
visitedViews
:
[],
cachedViews
:
[]
cachedViews
:
[],
key
:
null
}
const
mutations
=
{
setKey
:(
state
,
name
)
=>
{
state
.
key
=
name
||
null
},
ADD_VISITED_VIEW
:
(
state
,
view
)
=>
{
if
(
state
.
visitedViews
.
some
(
v
=>
v
.
path
===
view
.
path
))
return
state
.
visitedViews
.
push
(
...
...
@@ -130,6 +134,7 @@ const actions = {
delCachedView
({
commit
,
state
},
view
)
{
return
new
Promise
(
resolve
=>
{
commit
(
'DEL_CACHED_VIEW'
,
view
)
console
.
log
(
view
.
name
,
'当前清除缓存的view'
)
resolve
([...
state
.
cachedViews
])
})
},
...
...
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