From b7f4539e63fe1aae4b2548b532b046bbf9c5d018 Mon Sep 17 00:00:00 2001 From: zzp <34701892@qq.com> Date: Wed, 17 Sep 2025 15:33:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DJSON=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=B9=B6=E6=81=A2=E5=A4=8DAPI=E7=AB=AF?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复RankList组件中JSON.parse可能抛出异常的问题,添加try-catch处理 恢复newsInfo.ts中getTopNews的原始API端点 --- src/api/newsInfo.ts | 4 ++-- src/components/RankList.vue | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/api/newsInfo.ts b/src/api/newsInfo.ts index 8d873d8..662973e 100644 --- a/src/api/newsInfo.ts +++ b/src/api/newsInfo.ts @@ -17,8 +17,8 @@ export const getConceptCount = (data: any) => { // 概念标签贴标 export const getTopNews = (data: any) => { - // return request.get("/top_news_h5_d", data); - return request.get("/top_news_release_h5_all", data); + return request.get("/top_news_h5_d", data); + // return request.get("/top_news_release_h5_all", data); }; // 概念标签贴标 export const getTopNewsAll = (data: any) => { diff --git a/src/components/RankList.vue b/src/components/RankList.vue index f0a8576..f6e3a90 100644 --- a/src/components/RankList.vue +++ b/src/components/RankList.vue @@ -88,14 +88,20 @@ watch( (newValue, oldValue) => { rankListLocal.value = []; props.newsList.forEach((item, index) => { + console.log("🚀 ~ item:", item); if (!isExp.value && index > 9) { return; } - + let concept_label = ""; + let industry_label = ""; + try { + concept_label = JSON.parse(item.concept_label); + industry_label = JSON.parse(item.industry_label); + } catch (e) {} rankListLocal.value.push({ ...item, - conceptLabels: JSON.parse(item.concept_label), - industryLabels: JSON.parse(item.industry_label), + conceptLabels: concept_label, + industryLabels: industry_label, }); }); @@ -114,11 +120,17 @@ watch( if (!isExp.value && index > 9) { return; } + let concept_label = ""; + let industry_label = ""; + try { + concept_label = JSON.parse(item.concept_label); + industry_label = JSON.parse(item.industry_label); + } catch (e) {} rankListLocal.value.push({ ...item, - conceptLabels: JSON.parse(item.concept_label), - industryLabels: JSON.parse(item.industry_label), + conceptLabels: concept_label, + industryLabels: industry_label, }); }); loading.value = false;