封装scroll-view,把scroll-into-view作为props赋值
chentc
- 发布:2023-04-10 10:33
- 更新:2024-08-16 17:47
- 阅读:441
<scroll-view scroll-y="true" :scroll-into-view="scrollInto" @scroll="onScroll">
<block v-for="(item, index) in content" :key="index">
<view :id="''+index">{{item}}</view>
</block>
</scroll-view>
data() { return { /*竖向滚动条的位置*/ scrollInto: 'scr-0',content: [] } },
methods: { itemAdd() { var len = this.$data.content.length; this.$data.content.push('测试.' + len) ;this.$data.scrollInto = '' + len; } }
//原生组件,h5页面 不正常,微信小程序 正常;
//自定义组件,都不正常
//改成这个的代码,原生组件,都正常;
//自定义组件,h5 正常,微信小程序 不正常;
setTimeout(() => {;this.$data.scrollInto = '' + len;}, 200)
hbuilder x 4.24
WeChatLib: 3.5.4
1234554321
scroll-view :scroll-top="scrollTop" class="scroll-content"
data: {scrollHg: 0,scrollTop: 0}
uni.createSelectorQuery().select('.scroll-content').scrollOffset(rs=>{
if( page.scrollHg === 0 ){ page.$data.scrollHg = rs.scrollHeight; return; }
var hg = page.scrollHg;
if( hg != rs.scrollHeight ){
page.$data.scrollHg = rs.scrollHeight;
page.$data.scrollTop = rs.scrollHeight;
}
}).exec()
使用这种方式解决了
2024-08-19 11:35