fix: 页面卸载前判断是否断开ws

This commit is contained in:
TsMask
2024-04-17 10:45:45 +08:00
parent 17e72f1db1
commit f73c21e6e6
2 changed files with 10 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { reactive, onMounted, toRaw, ref, onUnmounted } from 'vue';
import { reactive, onMounted, toRaw, ref, onBeforeUnmount } from 'vue';
import { PageContainer } from 'antdv-pro-layout';
import { message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
@@ -366,8 +366,10 @@ onMounted(() => {
});
});
onUnmounted(() => {
ws.close();
onBeforeUnmount(() => {
if (ws.state() !== -1) {
ws.close();
}
});
</script>

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { reactive, onMounted, toRaw, ref, onUnmounted } from 'vue';
import { reactive, onMounted, toRaw, ref, onBeforeUnmount } from 'vue';
import { PageContainer } from 'antdv-pro-layout';
import { message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
@@ -394,8 +394,10 @@ onMounted(() => {
});
});
onUnmounted(() => {
ws.close();
onBeforeUnmount(() => {
if (ws.state() !== -1) {
ws.close();
}
});
</script>