@@ -612,6 +612,25 @@ export default {
612612 } ,
613613 immediate : true ,
614614 } ,
615+ /*
616+ watch virtualScrollOption enable
617+ 允许按需开启虚拟滚动
618+ */
619+ "virtualScrollOption.enable" : {
620+ handler ( newVal ) {
621+ // enable virtual scroll
622+ if ( newVal ) {
623+ this . initVirtualScrollPositions ( ) ;
624+ this . initVirtualScroll ( ) ;
625+ }
626+ // disable virtual scroll
627+ else {
628+ // clear table content top value
629+ this . setTableContentTopValue ( { top : 0 } ) ;
630+ }
631+ } ,
632+ immediate : false ,
633+ } ,
615634 } ,
616635
617636 methods : {
@@ -1304,11 +1323,15 @@ export default {
13041323 this . virtualScrollPositions [ start - 1 ] . bottom - size ;
13051324 }
13061325
1326+ this . setTableContentTopValue ( { top : startOffset } ) ;
1327+ } ,
1328+ // set table content top value
1329+ setTableContentTopValue ( { top } ) {
13071330 //this.$refs[this.tableContentRef].style.transform = `translate3d(0,${startOffset}px,0)`;
13081331 window . requestAnimationFrame ( ( ) => {
13091332 const ele = this . $refs [ this . tableContentRef ] ;
13101333 if ( ele ) {
1311- ele . $el . style . top = `${ startOffset } px` ;
1334+ ele . $el . style . top = `${ top } px` ;
13121335 }
13131336 } ) ;
13141337 } ,
@@ -1425,9 +1448,13 @@ export default {
14251448 this . virtualScrollEndIndex =
14261449 startIndex + this . virtualScrollVisibleCount ;
14271450
1428- const tableContainerRef = this . $refs [ this . tableContainerRef ] ;
1429- this . tableContainerVirtualScrollHandler ( tableContainerRef ) ;
1430- this . setVirtualPhantomHeight ( ) ;
1451+ // 修复渲染结束,同时开启虚拟滚动和设置表格数据,无法设置 virtual phantom 高度的问题
1452+ this . $nextTick ( ( ) => {
1453+ const tableContainerRef =
1454+ this . $refs [ this . tableContainerRef ] ;
1455+ this . tableContainerVirtualScrollHandler ( tableContainerRef ) ;
1456+ this . setVirtualPhantomHeight ( ) ;
1457+ } ) ;
14311458 }
14321459 } ,
14331460
0 commit comments