美文网首页
uniapp滚动到顶部

uniapp滚动到顶部

作者: 我是七月 | 来源:发表于2022-12-01 08:56 被阅读0次

由于scroll-view手动滚动时:scroll-top="contentTop"值不会变,所以当点击回到顶部时contentTop设置为初始值0不会刷新
解决方法:先将contentTop设为手动滚动时记录下的scrollTop,然后再设为0

<scroll-view  scroll-y="true" scroll-with-animation="true" :scroll-top="contentTop" @scroll="onScroll"></scroll-view>

        onGoTop(){
            this.leftCurrent=0
            this.contentTop=this.scrollTop
            this.$nextTick(()=>{
                this.contentTop=0
            })
        },


        onScroll(e){
            this.scrollTop=e.detail.scrollTop
        }

相关文章

网友评论

      本文标题:uniapp滚动到顶部

      本文链接:https://www.haomeiwen.com/subject/bsdefdtx.html