wuyouming666
2024-08-02 66ad819bd2e08f900f6b6249e74c74e9c761e4a6
UI-Project/src/views/Caching/cachingun.vue
@@ -60,7 +60,7 @@
const adda = ref(false)
import { WebSocketHost ,host} from '@/utils/constants'
import request from "@/utils/request"
import { ref, onMounted , onUnmounted} from "vue";
import { ref, onMounted , onBeforeUnmount,onUnmounted} from "vue";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
// import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -204,7 +204,8 @@
};
let socket =null;
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/unLoadGlass/api/talk/downcache`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
@@ -219,16 +220,17 @@
          })); 
};
// 初始化 WebSocket,并传递消息处理函数
onMounted(() => {
  // fetchFlowCardId();
  // fetchTableData(); // 获取数据
  socket =  initializeWebSocket(socketUrl, handleMessage);
  socket = initializeWebSocket(socketUrl, handleMessage);
});
onUnmounted(() => {
  onUnmounted(() => {
    if (socket) {
    closeWebSocket(socket);
    }
    });
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket(socket);
  closeWebSocket();
});
</script>
<style scoped>