1
1
<template >
2
- <view :class =" classes" @scroll.passive =" handleScrollEvent" ref =" list" >
2
+ <div :class =" classes" :style = " { height: `${getContainerHeight}px` } " @scroll.passive =" handleScrollEvent" ref =" list" >
3
3
<div class =" nut-list-phantom" :style =" { height: listHeight + 'px' }" ></div >
4
4
<div class =" nut-list-container" :style =" { transform: getTransform }" >
5
5
<div class =" nut-list-item" :style =" { height: height + 'px' }" v-for =" (item, index) in visibleData" :key =" item" >
6
6
<slot :item =" item" :index =" index" ></slot >
7
7
</div >
8
8
</div >
9
- </view >
9
+ </div >
10
10
</template >
11
11
<script lang="ts">
12
12
import { reactive , toRefs , computed , ref , Ref , watch } from ' vue' ;
13
13
import { createComponent } from ' @/packages/utils/create' ;
14
14
const { componentName, create } = createComponent (' list' );
15
+ const clientHeight = document .documentElement .clientHeight || document .body .clientHeight ;
15
16
export default create ({
16
17
props: {
17
18
height: {
@@ -26,7 +27,7 @@ export default create({
26
27
},
27
28
containerHeight: {
28
29
type: [Number ],
29
- default: document . documentElement . clientHeight || document . body . clientHeight || 667
30
+ default: clientHeight || 667
30
31
}
31
32
},
32
33
emits: [' scroll' , ' scroll-bottom' ],
@@ -39,8 +40,12 @@ export default create({
39
40
list: props .listData .slice ()
40
41
});
41
42
43
+ const getContainerHeight = computed (() => {
44
+ return Math .min (props .containerHeight , clientHeight );
45
+ });
46
+
42
47
const visibleCount = computed (() => {
43
- return Math .ceil (props . containerHeight / props .height );
48
+ return Math .ceil (getContainerHeight . value / props .height );
44
49
});
45
50
46
51
const end = computed (() => {
@@ -90,6 +95,7 @@ export default create({
90
95
listHeight ,
91
96
visibleData ,
92
97
classes ,
98
+ getContainerHeight ,
93
99
handleScrollEvent
94
100
};
95
101
}
0 commit comments