Commit 616c1b38 authored by 李苏's avatar 李苏 💬

路由基础页调整,需要功能页定义name对应路由name实现动态缓存

parent b6c9b8c6
Pipeline #279 canceled with stages
<template>
<!--
当每个页面赋值name
并且二级目录的路由标签组件也赋值name
name 对应路由name 使用include生效
换成如下方案
<template> <template>
<section class="app-main"> <section class="app-main">
<transition name="fade-transform" mode="out-in"> <transition name="fade-transform" mode="out-in">
...@@ -17,6 +13,7 @@ ...@@ -17,6 +13,7 @@
<script> <script>
export default { export default {
name: 'AppMain', name: 'AppMain',
computed: { computed: {
...@@ -30,75 +27,8 @@ ...@@ -30,75 +27,8 @@
} }
</script> </script>
-->
<section class="app-main">
<keep-alive>
<router-view v-if="showCache" />
</keep-alive>
<router-view v-if="!showCache" />
</section>
</template>
<script>
export default {
name: 'AppMain',
computed: {
cachedViews() {
return this.$store.state.tagsView.cachedViews
}
},
watch: {
/* 监听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) {
if(val.meta.noCache){
this.showCache = false
}else{
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>
<style lang="scss" scoped> <style lang="scss" scoped>
.app-main { .app-main {
......
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