xugenyuan

ref |> 解决评论重复问题

... ... @@ -256,11 +256,14 @@ export struct CommentComponent {
//获取数据
async getData() {
commentViewModel.fetchContentCommentList(this.currentPage + '', this.publishCommentModel.targetId,
let pageIndex = this.currentPage
commentViewModel.fetchContentCommentList(pageIndex + '', this.publishCommentModel.targetId,
this.publishCommentModel.targetType)
.then(commentListModel => {
console.log('评论:', JSON.stringify(commentListModel.list))
// 这里需要先赋值,否则下次UI刷新可能重复进入第1页两次
this.currentPage = pageIndex + 1
if (Number.parseInt(commentListModel.totalCommentNum) >
Number.parseInt(this.publishCommentModel.totalCommentNumer)) {
this.publishCommentModel.totalCommentNumer = commentListModel.totalCommentNum + ''
... ... @@ -278,7 +281,7 @@ export struct CommentComponent {
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
if (this.currentPage == 1) {
if (pageIndex == 1) {
this.allDatas.clearAllData() // 防止数据重复问题
}
commentListModel.list.forEach(element => {
... ... @@ -290,12 +293,9 @@ export struct CommentComponent {
this.allDatas.push(newModel)
});
} else {
this.hasMore = false
}
this.currentPage++
if (!this.fixedHeightMode && this.reachEndLoadMoreFinish) {
this.reachEndLoadMoreFinish()
}
... ...