设置 scroll-view
<scroll-view :scroll-y="true" :scroll-with-animation="true" :scroll-top="scrollTop" :style="`height:${height}px`">
<view v-for="item in 10" :id="`box${item}`">box {
{item}}</view>
</scroll-view>
scroll-y:设置为纵向
scroll-with-animation:在设置滚动条位置时使用动画过渡
scroll-top:设置竖向滚动条位置
如果是纵向一定要设置高度,不然不生效
scroll-view:scroll-view | uni-app官网
通过onLoad获取界面高度
const scrollTop = ref(0)
const height = ref(0)
onLoad(() => {
height.value = uni.getSystemInfoSync().win