Skip to content

Commit 64088fc

Browse files
committed
fix(list): 组件事件不被触发 #1607
1 parent 01faac5 commit 64088fc

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

src/packages/__VUE/list/doc.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ body {
9898
|--------------|----------------------------------|--------|------------------|
9999
| height | The height of the list item | Number | `50` |
100100
| list-data | List data | any[] | `[]` |
101-
| container-height `v3.1.19` | Container height | Number | `Visual area height` |
101+
| container-height `v3.1.19` | Container height(The maximum value cannot exceed the viewable area) | Number | `Visual area height` |
102102

103103
### Slot
104104

src/packages/__VUE/list/doc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ body {
9898
|--------------|----------------------------------|--------|------------------|
9999
| height | 列表项的高度 | Number | `50` |
100100
| list-data | 列表数据 | any[] | `[]` |
101-
| container-height `v3.1.19` | 容器高度 | Number | `可视区高度` |
101+
| container-height `v3.1.19` | 容器高度(最大值不能超过可视区) | Number | `可视区高度` |
102102

103103
### Slot
104104

src/packages/__VUE/list/index.scss

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.nut-list {
22
width: 100%;
3-
height: 100%;
43
overflow: scroll;
54
position: relative;
65
-webkit-overflow-scrolling: touch;

src/packages/__VUE/list/index.taro.vue

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<scroll-view
33
:class="classes"
44
:scroll-y="true"
5-
:style="{ height: containerHeight + 'px' }"
5+
:style="{ height: `${getContainerHeight}px` }"
66
scroll-top="0"
77
@scroll="handleScrollEvent"
88
ref="list"
@@ -20,6 +20,7 @@ import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
2020
import { createComponent } from '@/packages/utils/create';
2121
import Taro from '@tarojs/taro';
2222
const { componentName, create } = createComponent('list');
23+
const clientHeight = Taro.getSystemInfoSync().windowHeight;
2324
export default create({
2425
props: {
2526
height: {
@@ -34,7 +35,7 @@ export default create({
3435
},
3536
containerHeight: {
3637
type: [Number],
37-
default: Taro.getSystemInfoSync().windowHeight || 667
38+
default: clientHeight || 667
3839
}
3940
},
4041
emits: ['scroll', 'scroll-bottom'],
@@ -47,8 +48,12 @@ export default create({
4748
list: props.listData.slice()
4849
});
4950
51+
const getContainerHeight = computed(() => {
52+
return Math.min(props.containerHeight, clientHeight);
53+
});
54+
5055
const visibleCount = computed(() => {
51-
return Math.ceil(props.containerHeight / props.height);
56+
return Math.ceil(getContainerHeight.value / props.height);
5257
});
5358
5459
const end = computed(() => {
@@ -98,6 +103,7 @@ export default create({
98103
listHeight,
99104
visibleData,
100105
classes,
106+
getContainerHeight,
101107
handleScrollEvent
102108
};
103109
}

src/packages/__VUE/list/index.vue

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<template>
2-
<view :class="classes" @scroll.passive="handleScrollEvent" ref="list">
2+
<div :class="classes" :style="{ height: `${getContainerHeight}px` }" @scroll.passive="handleScrollEvent" ref="list">
33
<div class="nut-list-phantom" :style="{ height: listHeight + 'px' }"></div>
44
<div class="nut-list-container" :style="{ transform: getTransform }">
55
<div class="nut-list-item" :style="{ height: height + 'px' }" v-for="(item, index) in visibleData" :key="item">
66
<slot :item="item" :index="index"></slot>
77
</div>
88
</div>
9-
</view>
9+
</div>
1010
</template>
1111
<script lang="ts">
1212
import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
1313
import { createComponent } from '@/packages/utils/create';
1414
const { componentName, create } = createComponent('list');
15+
const clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
1516
export default create({
1617
props: {
1718
height: {
@@ -26,7 +27,7 @@ export default create({
2627
},
2728
containerHeight: {
2829
type: [Number],
29-
default: document.documentElement.clientHeight || document.body.clientHeight || 667
30+
default: clientHeight || 667
3031
}
3132
},
3233
emits: ['scroll', 'scroll-bottom'],
@@ -39,8 +40,12 @@ export default create({
3940
list: props.listData.slice()
4041
});
4142
43+
const getContainerHeight = computed(() => {
44+
return Math.min(props.containerHeight, clientHeight);
45+
});
46+
4247
const visibleCount = computed(() => {
43-
return Math.ceil(props.containerHeight / props.height);
48+
return Math.ceil(getContainerHeight.value / props.height);
4449
});
4550
4651
const end = computed(() => {
@@ -90,6 +95,7 @@ export default create({
9095
listHeight,
9196
visibleData,
9297
classes,
98+
getContainerHeight,
9399
handleScrollEvent
94100
};
95101
}

src/sites/mobile-taro/vue/src/exhibition/pages/list/index.vue

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ export default defineComponent({
3737
</script>
3838
<style lang="scss">
3939
.list-demo {
40-
.nut-cell {
41-
height: 100%;
42-
}
4340
.list-item {
4441
display: flex;
4542
align-items: center;

0 commit comments

Comments
 (0)