Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TianGongKaiWu-20251203
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
SparkProjects
TianGongKaiWu-20251203
Commits
a395e495
Commit
a395e495
authored
Dec 16, 2025
by
天马流星拳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(HomePage): 修复排行榜数据加载问题并添加错误处理
确保在组件挂载时先更新索引再获取排行榜数据 添加数据重置逻辑避免显示旧数据 增加API调用成功检查和错误处理
parent
46a0ae21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
HomePage.tsx
src/pages/HomePage/HomePage.tsx
+25
-9
No files found.
src/pages/HomePage/HomePage.tsx
View file @
a395e495
...
...
@@ -42,21 +42,37 @@ class HomePage extends React.Component<any, any> {
isExpand
:
false
,
};
componentDidMount
()
{
store
.
updateIndex
()
async
componentDidMount
()
{
// 确保索引数据更新完成后再获取排行榜信息
await
store
.
updateIndex
();
// 获取排行榜信息
this
.
getQueryRankInfo
(
this
.
state
.
rankingTab
);
}
// 获取排行榜信息
getQueryRankInfo
=
async
(
type
)
=>
{
console
.
log
(
"🚀 ~ HomePage ~ type:"
,
type
)
const
{
success
,
code
,
data
,
message
}
=
await
API
.
queryRankInfo
({
type
:
type
});
if
(
data
)
{
console
.
log
(
"🚀 ~ HomePage ~ type:"
,
type
)
;
try
{
// 先重置数据,避免切换时显示旧数据
this
.
setState
({
rankOptions
:
data
?.
rankOptions
||
[],
rankInfos
:
data
?.
rankInfos
||
[],
myRank
:
data
?.
myRank
||
{},
})
rankOptions
:
[],
rankInfos
:
[],
myRank
:
{},
});
const
{
success
,
code
,
data
,
message
}
=
await
API
.
queryRankInfo
({
type
:
type
});
// 检查API调用是否成功且有数据
if
(
success
&&
data
)
{
this
.
setState
({
rankOptions
:
data
?.
rankOptions
||
[],
rankInfos
:
data
?.
rankInfos
||
[],
myRank
:
data
?.
myRank
||
{},
});
}
else
{
console
.
warn
(
"获取排行榜数据失败:"
,
message
||
"未知错误"
);
}
}
catch
(
error
)
{
console
.
error
(
"查询排行榜信息时发生错误:"
,
error
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment