|
@@ -1,8 +1,8 @@
|
|
|
<template>
|
|
|
<section class="app-main">
|
|
|
<transition name="fade" mode="out-in">
|
|
|
- <keep-alive>
|
|
|
- <router-view :key="getKey()" v-if="$route.meta.keepAlive"></router-view>
|
|
|
+ <keep-alive :include="include">
|
|
|
+ <router-view v-if="$route.meta.keepAlive"></router-view>
|
|
|
</keep-alive>
|
|
|
</transition>
|
|
|
<transition name="fade" mode="out-in">
|
|
@@ -31,19 +31,26 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
watch:{
|
|
|
- // destroyPath(){
|
|
|
- // this.destroyComponent()
|
|
|
- // }
|
|
|
+ $route(to, from) {
|
|
|
+ if (to.meta.keepAlive) {
|
|
|
+ if(!this.include.includes(to.name)){
|
|
|
+ this.include.push(to.name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ destroyPath(){
|
|
|
+ this.destroyComponent()
|
|
|
+ },
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ include:[]
|
|
|
}
|
|
|
},
|
|
|
created(){
|
|
|
// if(this.userId){
|
|
|
// this.connectWebSocket(this.userId)
|
|
|
// }
|
|
|
- this.destroyComponent()
|
|
|
},
|
|
|
methods: {
|
|
|
getKey(){
|
|
@@ -51,10 +58,10 @@ export default {
|
|
|
},
|
|
|
destroyComponent(){
|
|
|
if(this.destroyPath){
|
|
|
- var dom = this.$refs[this.destroyPath]
|
|
|
- console.log(dom)
|
|
|
- if(dom){
|
|
|
- dom.$history()
|
|
|
+ var index = this.include.indexOf(this.destroyPath)
|
|
|
+ if(index !=-1){
|
|
|
+ this.include.splice(index, 1);
|
|
|
+ this.$store.commit('addDestroyPath',null)
|
|
|
}
|
|
|
}
|
|
|
},
|