浏览代码

fix(student): 修复WebSocket重复初始化问题

移除了onMounted中重复的WebSocket初始化代码,将其统一整合到getCourseDetail函数中,确保WebSocket仅在课程详情获取完成后且满足条件时初始化,避免重复创建连接。
lsc 14 小时之前
父节点
当前提交
23cb3097e6
共有 1 个文件被更改,包括 5 次插入 和 4 次删除
  1. 5 4
      src/views/Student/index.vue

+ 5 - 4
src/views/Student/index.vue

@@ -2846,6 +2846,10 @@ const getCourseDetail = async () => {
     console.log('操作记录:', opRes1[0])
     console.log('操作记录:', opRes.value)
     console.log(res, opRes.value)
+    // 初始化WebSocket连接
+    if (api.yweb_socket) {
+      createWebSocketConnection()
+    }
     const courseData = res[0][0]
     courseDetail.value = courseData
     selectWorksStudent()
@@ -4137,10 +4141,7 @@ onMounted(() => {
   console.log('PPTist Student View 已加载,可通过 window.PPTistStudent 访问功能')
   console.log('URL参数:', { courseid: props.courseid, type: props.type })
 
-  // 初始化WebSocket连接
-  if (api.yweb_socket) {
-    createWebSocketConnection()
-  }
+
 
   // 创建人离开页面时,广播停止计时