@@ -401,7 +401,8 @@ const gridContainerStyle = computed(() => ({
401401}))
402402
403403// 是否显示初始骨架屏(数据量不足阈值且还有更多内容时)
404- const showInitialSkeleton = computed (() => {
404+ // 改为计算是否需要填充骨架屏,而不是完全切换
405+ const needSkeletonPadding = computed (() => {
405406 if (props .needToLoginFirst )
406407 return false
407408 if (props .noMoreContent )
@@ -411,14 +412,18 @@ const showInitialSkeleton = computed(() => {
411412 return true
412413})
413414
414- // 生成初始骨架屏数据(仅用于首次加载 )
415- const initialSkeletonItems = computed (() => {
416- if (! showInitialSkeleton .value )
415+ // 生成填充骨架屏数据(填补到最小渲染数量 )
416+ const paddingSkeletonItems = computed (() => {
417+ if (! needSkeletonPadding .value )
417418 return []
418419
419- return Array .from ({ length: dynamicSkeletonCount .value }, (_ , i ) => ({
420+ const currentCount = props .items .length
421+ const targetCount = dynamicSkeletonCount .value
422+ const paddingCount = Math .max (0 , targetCount - currentCount )
423+
424+ return Array .from ({ length: paddingCount }, (_ , i ) => ({
420425 _isSkeleton: true ,
421- _skeletonId: ` skeleton-init -${i } ` ,
426+ _skeletonId: ` skeleton-padding -${i } ` ,
422427 })) as T []
423428})
424429
@@ -443,6 +448,11 @@ const loadingMoreSkeletonItems = computed(() => {
443448
444449// 合并实际数据和骨架屏
445450const displayItems = computed (() => {
451+ // 数据不足时:数据 + 填充骨架屏
452+ if (needSkeletonPadding .value ) {
453+ return [... props .items , ... paddingSkeletonItems .value ]
454+ }
455+
446456 // 加载更多时:数据 + 骨架屏
447457 if (isLoadingMore .value ) {
448458 return [... props .items , ... loadingMoreSkeletonItems .value ]
@@ -616,22 +626,8 @@ function getUniqueKey(item: T, index: number): string | number {
616626 m =" b-0 t-0" relative w-full
617627 :style =" gridContainerStyle"
618628 >
619- <!-- 初始加载骨架屏 -->
620- <div v-if =" showInitialSkeleton" :class =" gridClass" >
621- <VideoCard
622- v-for =" item in initialSkeletonItems"
623- :key =" (item as any)._skeletonId"
624- skeleton
625- :horizontal =" isHorizontal"
626- >
627- <template v-for =" (_ , name ) in $slots " #[name ]>
628- <slot :name =" name" :item =" item" />
629- </template >
630- </VideoCard >
631- </div >
632-
633- <!-- Grid 内容 -->
634- <div v-else :class =" gridClass" >
629+ <!-- Grid 内容(统一渲染,避免 v-if/v-else 切换导致的滚动跳动) -->
630+ <div :class =" gridClass" >
635631 <VideoCard
636632 v-for =" (item, index) in displayItems"
637633 :key =" getUniqueKey(item, index)"
0 commit comments