|
@@ -1,17 +1,18 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <view :class="classes" @scroll.passive="handleScrollEvent" ref="list">
|
|
|
|
|
|
|
+ <div :class="classes" :style="{ height: `${getContainerHeight}px` }" @scroll.passive="handleScrollEvent" ref="list">
|
|
|
<div class="nut-list-phantom" :style="{ height: listHeight + 'px' }"></div>
|
|
<div class="nut-list-phantom" :style="{ height: listHeight + 'px' }"></div>
|
|
|
<div class="nut-list-container" :style="{ transform: getTransform }">
|
|
<div class="nut-list-container" :style="{ transform: getTransform }">
|
|
|
<div class="nut-list-item" :style="{ height: height + 'px' }" v-for="(item, index) in visibleData" :key="item">
|
|
<div class="nut-list-item" :style="{ height: height + 'px' }" v-for="(item, index) in visibleData" :key="item">
|
|
|
<slot :item="item" :index="index"></slot>
|
|
<slot :item="item" :index="index"></slot>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- </view>
|
|
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
|
|
import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
|
|
|
import { createComponent } from '@/packages/utils/create';
|
|
import { createComponent } from '@/packages/utils/create';
|
|
|
const { componentName, create } = createComponent('list');
|
|
const { componentName, create } = createComponent('list');
|
|
|
|
|
+const clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
|
|
|
export default create({
|
|
export default create({
|
|
|
props: {
|
|
props: {
|
|
|
height: {
|
|
height: {
|
|
@@ -26,7 +27,7 @@ export default create({
|
|
|
},
|
|
},
|
|
|
containerHeight: {
|
|
containerHeight: {
|
|
|
type: [Number],
|
|
type: [Number],
|
|
|
- default: document.documentElement.clientHeight || document.body.clientHeight || 667
|
|
|
|
|
|
|
+ default: clientHeight || 667
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
emits: ['scroll', 'scroll-bottom'],
|
|
emits: ['scroll', 'scroll-bottom'],
|
|
@@ -39,8 +40,12 @@ export default create({
|
|
|
list: props.listData.slice()
|
|
list: props.listData.slice()
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const getContainerHeight = computed(() => {
|
|
|
|
|
+ return Math.min(props.containerHeight, clientHeight);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const visibleCount = computed(() => {
|
|
const visibleCount = computed(() => {
|
|
|
- return Math.ceil(props.containerHeight / props.height);
|
|
|
|
|
|
|
+ return Math.ceil(getContainerHeight.value / props.height);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const end = computed(() => {
|
|
const end = computed(() => {
|
|
@@ -90,6 +95,7 @@ export default create({
|
|
|
listHeight,
|
|
listHeight,
|
|
|
visibleData,
|
|
visibleData,
|
|
|
classes,
|
|
classes,
|
|
|
|
|
+ getContainerHeight,
|
|
|
handleScrollEvent
|
|
handleScrollEvent
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|