Przeglądaj źródła

fix(student page): add error handling for json parse of result array

add try-catch to handle invalid json string when parsing isResultArray,
set default empty array when parse fails and log error
lsc 4 tygodni temu
rodzic
commit
f057f322ec
1 zmienionych plików z 7 dodań i 1 usunięć
  1. 7 1
      src/views/Student/index.vue

+ 7 - 1
src/views/Student/index.vue

@@ -3696,7 +3696,13 @@ const getMessages = (msgObj: any) => {
 
   // 获取是否展开结果数组
   if (props.type == '2' && msgObj.type === 'isResultArray' && msgObj.courseid === props.courseid) {
-    isResultArray.value = JSON.parse(msgObj.isResultArray || '[]')
+    try {
+      isResultArray.value = JSON.parse(msgObj.isResultArray || '[]')
+    }
+    catch (error) {
+      console.error('解析是否展开结果数组失败:', error)
+      isResultArray.value = []
+    }
     if (isResultArray.value.length > 0 ) {
       const result = isResultArray.value[slideIndex.value]
       console.log('是否展开结果数组:', result)