|
@@ -0,0 +1,34 @@
|
|
|
+import { keepAliveRoutesPairs } from "@/constant/constants";
|
|
|
+import Vue from "vue";
|
|
|
+
|
|
|
+Vue.mixin({
|
|
|
+ beforeRouteEnter(to, from, next) {
|
|
|
+ next((vm) => {
|
|
|
+ const tos = keepAliveRoutesPairs.map((v) => v[0]);
|
|
|
+ if (
|
|
|
+ tos.includes(to.name) &&
|
|
|
+ vm.$store.state.keepAliveRoutes.length === 0
|
|
|
+ ) {
|
|
|
+ vm.$store.commit("setRestoreKeepAliveRoutes");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ beforeRouteLeave(to, from, next) {
|
|
|
+ console.log(from.name, to.name);
|
|
|
+ const froms = keepAliveRoutesPairs.map((v) => v[0]);
|
|
|
+ if (
|
|
|
+ (froms.includes(from.name) &&
|
|
|
+ keepAliveRoutesPairs[froms.indexOf(from.name)][1].includes(to.name)) ||
|
|
|
+ (froms.includes(to.name) &&
|
|
|
+ keepAliveRoutesPairs[froms.indexOf(to.name)][1].includes(from.name))
|
|
|
+ ) {
|
|
|
+ // 减少无谓的commit
|
|
|
+ if (this.$store.state.keepAliveRoutes.length === 0)
|
|
|
+ this.$store.commit("setRestoreKeepAliveRoutes");
|
|
|
+ } else {
|
|
|
+ if (this.$store.state.keepAliveRoutes.length > 0)
|
|
|
+ this.$store.commit("setEmptyKeepAliveRoutes");
|
|
|
+ }
|
|
|
+ next();
|
|
|
+ },
|
|
|
+});
|