Commit 5625c0e1 by lijiabin

【需求 25171】fix: 修复问吧评论区首次无评论时查询参数缺失导致报错

问吧内联评论组件用 v-show 常驻挂载,commentId 只在组件创建时决定 searchParams
走 pid 分支还是 articleId 分支。某个问题/回答一开始没有评论时 commentId 是
undefined,组件锁死用 articleId 分支初始化;之后哪怕父组件传入了真实的
commentId,组件不会重新 mount,再次搜索时依然带着 articleId 请求
getQuestionComment,后端提示"参数缺失"。现在改成在真正发起搜索前校正一次
searchParams,commentId 一旦有值就切到 pid 分支。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
parent 0ddc8e7d
......@@ -498,6 +498,24 @@ const {
immediate,
})
// 问吧场景下,commentId(对应回答自己的评论 id)一开始可能还没有——比如某个问题/回答刚发布、
// 还没有第一条评论时,askTab/questionDetail 传进来的 commentId 是 undefined,这个 Comment 实例
// 会用 articleId 分支初始化 searchParams;之后一旦这个问题/回答有了第一条评论,父组件会把真实的
// commentId 传进来,但组件不会重新 mount,searchParams 不会自动跟着换成 pid 分支,
// 导致后续 search() 还是带着 articleId 去查 getQuestionComment,后端报"参数缺失"。
// 在真正发起搜索前校正一次 searchParams,而不是被动 watch commentId。
let syncedCommentId: number | undefined
const syncSearchTarget = () => {
if (!isQuestion || !commentId || syncedCommentId === commentId) return
syncedCommentId = commentId
searchParams.value = {
current: searchParams.value.current,
size: searchParams.value.size,
sortType: searchParams.value.sortType,
pid: commentId,
} as unknown as typeof searchParams.value
}
const commentSortOptions = [
{ label: '最高点赞', value: CommentSortTypeEnum.MOST_LIKE },
{ label: '最多评论', value: CommentSortTypeEnum.MOST_COMMENT },
......@@ -720,7 +738,10 @@ const getCurrentChildrenList = (item: CommentItemDto) => {
defineExpose({
scrollToCommentBox: () => handleBackTop(),
search: () => search(),
search: () => {
syncSearchTarget()
return search()
},
})
</script>
<style scoped lang="scss">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment