@@ -0,0 +1,51 @@
<!-- pagesA -->
<script>
export default {
onPageScroll(e) {
// 记录当前滚动位置
uni.setStorageSync('scrollPosition', e.scrollTop);
},
onShow() {
// 获取页面滚动距离
this.scroll = uni.getStorageSync('scroll');
// 单用uni.pageScrollTo可能会失效,加上setTimeout就万无一失
setTimeout(() => {
uni.pageScrollTo({
scrollTop: this.scroll,
duration: 0, // 间隔时间
});
}, 100);
// 一定要加这个时间
},
methods: {
// pageA中点击某个按钮触发
jump() {
const scrollPosition = uni.getStorageSync('scrollPosition');
uni.navigateTo({
url:
'/pagesC/catCard/editImage?data=' +
list +
'&scroll=' +
scrollPosition,
});
},
},
};
</script>
<!-- pagesB -->
<script>
export default {
async onLoad(options) {
this.scroll = options.scroll;
}
methods: {
jump() {
// 屏幕滚动的记录
uni.setStorageSync('scroll', this.scroll);
this.app.goPage(-1);
}
}
};
</script>
页面切换时保持滚动距离
猜你喜欢
转载自blog.csdn.net/weixin_44696269/article/details/132530351
今日推荐
周排行