Skip to content

Commit

Permalink
feat: 添加tagOnClick标签切换全局公共事件
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Jan 9, 2025
1 parent e1cd14a commit a0246e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/layout/components/lay-tag/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ function tagOnClick(item) {
} else {
router.push({ path });
}
emitter.emit("tagOnClick", item);
}
onClickOutside(contextmenuRef, closeMenu, {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/mitt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import mitt from "mitt";
/** 全局公共事件需要在此处添加类型 */
type Events = {
openPanel: string;
tagViewsChange: string;
tagViewsShowModel: string;
tagOnClick: string;
logoChange: boolean;
tagViewsChange: string;
changLayoutRoute: string;
tagViewsShowModel: string;
imageInfo: {
img: HTMLImageElement;
height: number;
Expand Down

1 comment on commit a0246e3

@xiaoxian521
Copy link
Member Author

@xiaoxian521 xiaoxian521 commented on a0246e3 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用法如下:

<script setup lang="ts">
import { emitter } from "@/utils/mitt";
import { onMounted, onBeforeUnmount } from "vue";

onMounted(() => {
  emitter.on("tagOnClick", tag => {
    console.log("tag", tag);
  });
});

onBeforeUnmount(() => {
  // 解绑`tagOnClick`公共事件,防止多次触发
  emitter.off("tagOnClick");
});
</script>

Please sign in to comment.