解决虚拟滚动配合keep-alive,active数据恢复后页面卡顿、内存飙升的问题

This commit is contained in:
zhangz
2024-06-21 16:07:21 +08:00
parent 47fd44b0ce
commit f301c4a2df
3 changed files with 10 additions and 8 deletions

View File

@@ -1680,7 +1680,7 @@ const Methods = {
/**
* 刷新滚动操作,手动同步滚动相关位置(对于某些特殊的操作,比如滚动条错位、固定列不同步)
*/
refreshScroll () {
refreshScroll (clearVirtualScroll = true) {
const { lastScrollLeft, lastScrollTop } = this
const { $refs } = this
const { tableBody, leftBody, rightBody, tableFooter } = $refs
@@ -1690,7 +1690,7 @@ const Methods = {
const tableFooterElem = tableFooter ? tableFooter.$el : null
// 还原滚动条位置
if (lastScrollLeft || lastScrollTop) {
return restoreScrollLocation(this, lastScrollLeft, lastScrollTop)
return restoreScrollLocation(this, lastScrollLeft, lastScrollTop, clearVirtualScroll)
}
// 重置
setScrollTop(tableBodyElem, lastScrollTop)
@@ -4353,7 +4353,7 @@ const Methods = {
/**
* 手动清除滚动相关信息,还原到初始状态
*/
clearScroll () {
clearScroll (clearVirtualScroll = true) {
const { $refs, scrollXStore, scrollYStore } = this
const { tableBody, rightBody, tableFooter } = $refs
const tableBodyElem = tableBody ? tableBody.$el : null
@@ -4371,8 +4371,10 @@ const Methods = {
tableBodyElem.scrollTop = 0
tableBodyElem.scrollLeft = 0
}
scrollXStore.startIndex = 0
scrollYStore.startIndex = 0
if (clearVirtualScroll) {
scrollXStore.startIndex = 0
scrollYStore.startIndex = 0
}
return this.$nextTick()
},
/**

View File

@@ -913,7 +913,7 @@ export default {
this.preventEvent(null, 'mounted')
},
activated () {
this.recalculate().then(() => this.refreshScroll())
this.recalculate().then(() => this.refreshScroll(false))
this.preventEvent(null, 'activated')
},
deactivated () {

View File

@@ -8,8 +8,8 @@ const lineOffsetSizes = {
medium: 1
}
export function restoreScrollLocation (_vm, scrollLeft, scrollTop) {
return _vm.clearScroll().then(() => {
export function restoreScrollLocation (_vm, scrollLeft, scrollTop, clearVirtualScroll = true) {
return _vm.clearScroll(clearVirtualScroll).then(() => {
if (scrollLeft || scrollTop) {
// 重置最后滚动状态
_vm.lastScrollLeft = 0