Commit 98268ca7 authored by 李苏's avatar 李苏 💬

自定义页面缓存

parent 5b6b09c0
<template> <template>
<section class="app-main"> <section class="app-main">
<keep-alive v-if="cachedViews.includes(key)" > <keep-alive>
<router-view :key="key" /> <router-view v-if="showCache" />
</keep-alive> </keep-alive>
<router-view v-else :key="key" /> <router-view v-if="!showCache" />
</section> </section>
</template> </template>
<script> <script>
export default { export default {
name: 'AppMain', name: 'AppMain',
computed: { computed: {
cachedViews() { cachedViews() {
return this.$store.state.tagsView.cachedViews return this.$store.state.tagsView.cachedViews
}
}, },
key() { watch: {
return this.$route.name /* 监听cache*/
cachedViews(val) {
this.JSONcachedViews = JSON.stringify(val)
},
/* 监听tagADD*/
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) {
let name = val.name
if (this.addBz) {
if (this.cacheList.includes(name)) {
this.showCache = false
} else {
this.cacheList.push(name)
this.showCache = true
}
this.addBz = false
} else {
this.showCache = true
}
}
},
data() {
return {
/* 缓存标记*/
showCache: true,
/* 存储新旧缓存列表*/
JSONcachedViews: '',
/* tag新增标记*/
addBz: false,
/* cache列表*/
cacheList: [],
}
} }
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.app-main {
/* 50= navbar 50 */
min-height: calc(100vh - 50px);
width: 100%;
position: relative;
overflow: hidden;
}
.fixed-header+.app-main {
padding-top: 50px;
}
.hasTagsView {
.app-main { .app-main {
/* 84 = navbar + tags-view = 50 + 34 */ /* 50= navbar 50 */
min-height: calc(100vh - 84px); min-height: calc(100vh - 50px);
width: 100%;
position: relative;
overflow: hidden;
} }
.fixed-header+.app-main { .fixed-header+.app-main {
padding-top: 84px; padding-top: 50px;
}
.hasTagsView {
.app-main {
/* 84 = navbar + tags-view = 50 + 34 */
min-height: calc(100vh - 84px);
}
.fixed-header+.app-main {
padding-top: 84px;
}
} }
}
</style> </style>
<style lang="scss"> <style lang="scss">
// fix css style bug in open el-dialog // fix css style bug in open el-dialog
.el-popup-parent--hidden { .el-popup-parent--hidden {
.fixed-header { .fixed-header {
padding-right: 17px; padding-right: 17px;
}
} }
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment