删除前端列表的某一条数据,这时候数据删除了如果不重置所有数据,那下一次加载就会少加载一条数据
比如一次加载1 2 3 4 5,你把3删了,那后端会认为第二页是7 8 9 10 11,6就会少加载(因为第一页就是1 2 4 5 6),怎么办呢?
删除一条数据之后,继续调用拿取列表的分页API,然后只拿最后一条数据追加到正在渲染的数组里面即可。
getCollectionLists (afterDelete) {
if (!afterDelete) {
this.collectionList = this.paged.currentPage === 1 ? [] : this.collectionList
}
let params = {
pageIndex: this.paged.currentPage,
pageSize: this.paged.pageSize,
userId: this.userId
}
memberService.getCollectionList(params).then(resp => {
if (resp.statusCode === 200) {
let collectionList = resp.data.item
if (afterDelete) {
if (collectionList && collectionList.length === 10) {
this.collectionList.push(collectionList[collectionList.length - 1])
}
} else {
this.collectionList.push(...collectionList)
}
this.paged = resp.data.paged
}
})
},
deleteCollections (favoriteId, index) {
memberService.deleteCollection(favoriteId).then(resp => {
if (resp.statusCode === 200) {
this.collectionList.splice(index, 1)
if (this.paged.currentPage <= this.paged.pageCount) {
this.getCollectionLists(true)
}
CommonUtil.toast('取消收藏成功')
}
})
}