fix: 对未解绑的公共事件,在页面销毁时解绑

This commit is contained in:
xiaoxian521
2023-06-09 18:03:37 +08:00
parent ba2ec8aca2
commit c06ce94746
6 changed files with 43 additions and 46 deletions

View File

@@ -7,9 +7,9 @@ import leftCollapse from "./leftCollapse.vue";
import { useNav } from "@/layout/hooks/useNav";
import { storageLocal } from "@pureadmin/utils";
import { responsiveStorageNameSpace } from "@/config";
import { ref, computed, watch, onBeforeMount } from "vue";
import { findRouteByPath, getParentPaths } from "@/router/utils";
import { usePermissionStoreHook } from "@/store/modules/permission";
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
const route = useRoute();
const showLogo = ref(
@@ -51,12 +51,6 @@ function getSubMenuData(path: string) {
getSubMenuData(route.path);
onBeforeMount(() => {
emitter.on("logoChange", key => {
showLogo.value = key;
});
});
watch(
() => [route.path, usePermissionStoreHook().wholeMenus],
() => {
@@ -65,6 +59,17 @@ watch(
menuSelect(route.path, routers);
}
);
onMounted(() => {
emitter.on("logoChange", key => {
showLogo.value = key;
});
});
onBeforeUnmount(() => {
// 解绑`logoChange`公共事件,防止多次触发
emitter.off("logoChange");
});
</script>
<template>