<keep-alive><router-view v-if="$route.meta.keepalive" :key="key" /></keep-alive><router-view v-if="!$route.meta.keepalive" :key="key" />
pageDelete(id, tag) {this.$store.commit('tagBar/tagDelete', id)}
//从store 去除删除的内容标识;
import { mapGetters } from 'vuex'
computed: {
...mapGetters(['closeTagName'])
},
/******** 其他内容略过 ********/
// 路由离开,处理需要销毁的内容
beforeRouteLeave(to, from, next) {
if (this.closeTagName === '添加客户') {
this.$router.history.current.meta.keepalive = false
// 设置下一个路由的 meta
to.meta.keepAlive = false // 不缓存
this.$store.commit('tagBar/setCloseTagName')
} else {
this.$router.history.current.meta.keepalive = true
// 设置下一个路由的 meta
to.meta.keepAlive = true // 不缓存
}
next()
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69985427/viewspace-2728485/ ,如需转载,请注明出处,否则将追究法律责任。