Skip to content

Commit

Permalink
fix: ali&web环境scrollTop初始化不生效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lareinayanyu committed Jan 23, 2025
1 parent e93b931 commit db5ed91
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<scroll-view
class="mpx-recycle-list"
scroll-y="{{scrollY}}"
scroll-top="{{scrollTop}}"
scroll-top="{{_scrollTop}}"
scroll-with-animation="{{scrollWithAnimation}}"
enable-back-to-top="{{enableBackToTop}}"
lower-threshold="{{lowerThreshold}}"
Expand Down Expand Up @@ -73,7 +73,8 @@ createComponent({
end: 0,
contentStyle: '',
placeholderStyle: '',
positions: []
positions: [],
isReady: false
},
computed: {
_width() {
Expand All @@ -90,6 +91,10 @@ createComponent({
}
})
},
_scrollTop() {
// 使用初始值或当前值
return this.isReady ? this.scrollTop : 0
},
visibleCount() {
return Math.ceil(this.containerHeight / this.itemSize.height)
},
Expand All @@ -116,6 +121,11 @@ createComponent({
// 更新列表总高度
const height = this.positions[this.positions.length - 1].bottom
this.placeholderStyle = `height: ${height}px`
if (!this.isReady) {
this.$nextTick(() => {
this.isReady = true
})
}
// 更新真实偏移量
this.setStartOffset()
})
Expand All @@ -127,7 +137,8 @@ createComponent({
this.start = this.getStartIndex(val)
this.end = this.start + this.visibleCount
this.setStartOffset()
}
},
immediate: true
}
},
ready() {
Expand Down Expand Up @@ -212,7 +223,7 @@ createComponent({
"component": true,
"componentGenerics": {
"recycle-item": {
"default": "./mpx-recycle-item-default"
"default": "./mpx-recycle-item-default.mpx"
}
}
}
Expand Down

0 comments on commit db5ed91

Please sign in to comment.