xugenyuan

ref |> 解决评论重复问题

@@ -256,11 +256,14 @@ export struct CommentComponent { @@ -256,11 +256,14 @@ export struct CommentComponent {
256 256
257 //获取数据 257 //获取数据
258 async getData() { 258 async getData() {
259 - commentViewModel.fetchContentCommentList(this.currentPage + '', this.publishCommentModel.targetId, 259 + let pageIndex = this.currentPage
  260 + commentViewModel.fetchContentCommentList(pageIndex + '', this.publishCommentModel.targetId,
260 this.publishCommentModel.targetType) 261 this.publishCommentModel.targetType)
261 .then(commentListModel => { 262 .then(commentListModel => {
262 console.log('评论:', JSON.stringify(commentListModel.list)) 263 console.log('评论:', JSON.stringify(commentListModel.list))
263 264
  265 + // 这里需要先赋值,否则下次UI刷新可能重复进入第1页两次
  266 + this.currentPage = pageIndex + 1
264 if (Number.parseInt(commentListModel.totalCommentNum) > 267 if (Number.parseInt(commentListModel.totalCommentNum) >
265 Number.parseInt(this.publishCommentModel.totalCommentNumer)) { 268 Number.parseInt(this.publishCommentModel.totalCommentNumer)) {
266 this.publishCommentModel.totalCommentNumer = commentListModel.totalCommentNum + '' 269 this.publishCommentModel.totalCommentNumer = commentListModel.totalCommentNum + ''
@@ -278,7 +281,7 @@ export struct CommentComponent { @@ -278,7 +281,7 @@ export struct CommentComponent {
278 281
279 if (commentListModel && commentListModel.list && commentListModel.list.length > 0) { 282 if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
280 283
281 - if (this.currentPage == 1) { 284 + if (pageIndex == 1) {
282 this.allDatas.clearAllData() // 防止数据重复问题 285 this.allDatas.clearAllData() // 防止数据重复问题
283 } 286 }
284 commentListModel.list.forEach(element => { 287 commentListModel.list.forEach(element => {
@@ -290,12 +293,9 @@ export struct CommentComponent { @@ -290,12 +293,9 @@ export struct CommentComponent {
290 this.allDatas.push(newModel) 293 this.allDatas.push(newModel)
291 }); 294 });
292 295
293 -  
294 } else { 296 } else {
295 this.hasMore = false 297 this.hasMore = false
296 } 298 }
297 -  
298 - this.currentPage++  
299 if (!this.fixedHeightMode && this.reachEndLoadMoreFinish) { 299 if (!this.fixedHeightMode && this.reachEndLoadMoreFinish) {
300 this.reachEndLoadMoreFinish() 300 this.reachEndLoadMoreFinish()
301 } 301 }