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

@@ -1,7 +1,6 @@
<script setup lang="ts">
import { ref } from "vue";
import { list } from "./high/list";
import { ref, nextTick } from "vue";
import { emitter } from "@/utils/mitt";
defineOptions({
name: "PureTableHigh"
@@ -10,11 +9,6 @@ defineOptions({
const selected = ref(0);
function tabClick({ index }) {
if (index == 0) {
nextTick(() => {
emitter.emit("setAdaptive");
});
}
selected.value = index;
}
</script>

View File

@@ -1,7 +1,6 @@
<script setup lang="ts">
import { ref } from "vue";
import { useColumns } from "./columns";
import { emitter } from "@/utils/mitt";
import { ref, onMounted, onBeforeUnmount } from "vue";
const tableRef = ref();
@@ -15,18 +14,6 @@ const {
onSizeChange,
onCurrentChange
} = useColumns();
onMounted(() => {
emitter.on("setAdaptive", () => {
// 设置表格自适应高度(用于表格外的元素高度改变或者元素隐藏时主动对表格进行自适应高度调整)
tableRef.value.setAdaptive();
});
});
onBeforeUnmount(() => {
// 解绑`setAdaptive`公共事件,防止多次触发
emitter.off("setAdaptive");
});
</script>
<template>