uni-app nvue页面scroll嵌套list组件,list的高度影响了scroll横线滚动的可滑动位置

uni-app nvue页面scroll嵌套list组件,list的高度影响了scroll横线滚动的可滑动位置

开发环境 版本号 项目创建方式
Windows win10企业版 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

HBuilderX类型:正式

HBuilderX版本号:3.2.9

手机系统:iOS

手机系统版本号:IOS 14

手机厂商:苹果

手机机型:iPhone7

页面类型:nvue

打包方式:离线

项目创建方式:HBuilderX

示例代码:

<template>  
<view>  
<scroller scroll-direction="horizontal"  
bounce="false"
        class="data-container"  
show-scrollbar="false"
    >
    <list :show-scrollbar="false" class="room-state-x" :bounce="false" :style="{width: `${data.length*132}rpx`, height: height+'px'}">
        <header :style="{width: `${data.length*132}rpx}`}">
            <view class="row" :style="{width: `${data.length*132}rpx}`}">
                <view v-for="(item,index) in data" class="text-box-column" :key="'date'+index">
                    <text>{{item}}</text>
                </view>
            </view>
        </header>
        <cell v-for="(item,index) in list" :key="index" :style="{width: `${data.length*132}rpx}`}">
            <view class="row" :style="{width: `${data.length*132}rpx}`}">
                <view v-for="($item,i) in item" :key="i" class="text-box-column">
                    <text>{{$item}}</text>
                </view>
            </view>
        </cell>
    </list>
</scroller>
</view>
</template>  

<script>
export default {
data() {
return {
data: [],
list: [],
height: 0
}
},  
onShow() {  
this.height = uni.getSystemInfoSync().windowHeight  
},  
mounted() {  
uni.hideTabBar()  
for(let i=0; i< 30; i++) {  
this.data.push(i)  
this.list[i] = []  
for(let k=0; k<30;k++) {  
this.list[i].push(i*k+k+i)  
}  
}  
},  
methods: {  

}  
}
</script>  

<style>
.data-container{
width: 750rpx;
left: 0;
top: 0;
position: fixed;
bottom: 0;
background-color: #FFFFFF;
}
.text-box-column{
height: 128rpx;
justify-content: center;
flex-direction: column;
align-items: center;
border-right-width: 1rpx;
border-bottom-width: 1rpx;
border-top-width: 1rpx;
border-color: #EEEEEE;
width: 132rpx;
color: #FFFFFF;
background-color: #FFFFFF;
}
</style>  

操作步骤:

  • 横向滑动的距离跟高度相关,紧可滑动一小部分

预期结果:

  • 预期能滑动出全部设置宽度的内容

实际结果:

  • 紧可展示部分内容,猜测是跟高度相关

bug描述:

nvue页面scroll嵌套list组件,实现横向滑动及纵向滑动,scroll组件fix定位及设置横向滑动属性,list组件设置动态宽度及屏幕可视区域高度,报[bug]横向滑动的距离跟list的高度相关,不能全部滑动出设置宽度的内容


更多关于uni-app nvue页面scroll嵌套list组件,list的高度影响了scroll横线滚动的可滑动位置的实战教程也可以访问 https://www.itying.com/category-93-b0.html

26 回复

Bug已确认

更多关于uni-app nvue页面scroll嵌套list组件,list的高度影响了scroll横线滚动的可滑动位置的实战教程也可以访问 https://www.itying.com/category-93-b0.html


<template> <view> <scroller scroll-direction="horizontal" :bounce="false" class="data-container" :show-scrollbar="false" > <list :show-scrollbar="false" class="room-state-x" :bounce="false" :style="{width: `${data.length*132}rpx`, height: height+'px'}">
<view class="row" :style="{width: `${data.length*132}rpx`}"> <view v-for="(item,index) in data" class="text-box-column" :key="'date'+index"> <text>{{item}}</text> </view> </view>
<cell v-for="(item,index) in list" :key="index" :style="{width: `${data.length*132}rpx`}"> <view class="row" :style="{width: `${data.length*132}rpx`}"> <view v-for="($item,i) in item" :key="i" class="text-box-column"> <text>{{$item}}</text> </view> </view> </cell> </list> </scroller> </view> </template> <script> export default { data() { return { data: [], list: [], height: 0 } }, onShow() { this.height = uni.getSystemInfoSync().windowHeight }, mounted() { uni.hideTabBar() for(let i=0; i< 30; i++) { this.data.push(i) this.list[i] = [] for(let k=0; k<30;k++) { this.list[i].push(i*k+k+i) } } }, methods: { } } </script> <style> .data-container{ width: 750rpx; left: 0; top: 0; position: fixed; bottom: 0; background-color: #FFFFFF; } .text-box-column{ height: 128rpx; justify-content: center; flex-direction: column; align-items: center; border-right-width: 1rpx; border-bottom-width: 1rpx; border-top-width: 1rpx; border-color: #EEEEEE; width: 132rpx; color: #FFFFFF; background-color: #FFFFFF; } </style>

从这段代码上哪里可以确定横向没有滑动出全部内容,请录个视频看看效果

老师,安卓与ios的视频录制都在压缩包里,2端表现不一致,烦请查看一下

老师,安卓与ios的视频录制都在压缩包里,2端表现不一致,烦请查看一下

bug已确认,设置 position: fixed; 排版计算有问题,当然版本解决方案去掉 position: fixed;

ios去掉fixed之后效果并没有变化,老师,代码及视频在下面

<template> <view> <scroller scroll-direction="horizontal" :bounce="false" class="data-container" :show-scrollbar="false" :style="{height: height+'px'}" > <list :show-scrollbar="false" class="room-state-x" :bounce="false" :style="{width: `${data.length*132}rpx`, height: height+'px'}">
<view class="row" :style="{width: `${data.length*132}rpx`}"> <view v-for="(item,index) in data" class="text-box-column" :key="'date'+index"> <text>{{item}}</text> </view> </view>
<cell v-for="(item,index) in list" :key="index" :style="{width: `${data.length*132}rpx`}"> <view class="row" :style="{width: `${data.length*132}rpx`}"> <view v-for="($item,i) in item" :key="i" class="text-box-column"> <text>{{$item}}</text> </view> </view> </cell> </list> </scroller> </view> </template> <script> export default { data() { return { data: [], list: [], height: 0 } }, onShow() { this.height = uni.getSystemInfoSync().windowHeight }, mounted() { uni.hideTabBar() for(let i=0; i< 30; i++) { this.data.push(i) this.list[i] = [] for(let k=0; k<30;k++) { this.list[i].push(i*k+k+i) } } }, methods: { } } </script> <style> .data-container{ width: 750rpx; /* left: 0; top: 0; position: fixed; bottom: 0; */ background-color: #FFFFFF; } .text-box-column{ height: 128rpx; justify-content: center; flex-direction: column; align-items: center; border-right-width: 1rpx; border-bottom-width: 1rpx; border-top-width: 1rpx; border-color: #EEEEEE; width: 132rpx; color: #FFFFFF; background-color: #FFFFFF; } </style>

上面的测试代码缺少相关样式 例如 row,我们测试的结果和你的不一致,请提供一个简单完整的测试工程

回复 DCloud_uniad_HDX: demo在下面,麻烦看一下,谢谢

老师,这个是一个简单的demo,麻烦看一下

回复 DCloud_IOS_XTY: 安卓是可以的,ios不设置height直接无法横向滚动,如果设置了大于750rpx的话还能滑动一点点

你可以临时先不设height避开此问题

回复 DCloud_IOS_XTY: 不设置height安卓正常,ios无法横向滑动

回复 7***@qq.com: 加你q了通过下在q上沟通下

回复 DCloud_IOS_XTY: 请问好久修复呢,这次版本更新也没看到修复

回复 7***@qq.com: 修复了

回复 DCloud_IOS_XTY: 没看到效果呢,用编辑器的基座还是不行,用你发给我那个基座就可以

回复 7***@qq.com: 是用的alpha版吗?alpha版已修复

回复 DCloud_IOS_XTY: 好的,我试一下,我现在用的标准版的

请问官方什么时候能解决该问题,我们项目主要业务遇到了该问题,导致目前无法上线,十分紧急,非常感谢!!!

上边fixed 的问题下个版本修复

回复 DCloud_IOS_XTY: 谢谢

回复 DCloud_IOS_XTY: 请问下个版本有预计时间吗,该问题等待修复,谢谢

这是一个典型的 nvue 中滚动容器嵌套问题。在 nvue 中,scrollerlist 都是原生组件,它们的嵌套行为与 web 容器不同。

问题分析:

  1. scroller 设置为横向滚动,其内部 list 设置了固定高度(屏幕高度)
  2. list 本身也是一个可滚动的容器(纵向),当它被嵌套在横向 scroller 中时,两个滚动容器会相互影响
  3. nvue 的原生滚动容器在嵌套时,父容器的可滚动区域会受到子容器尺寸的影响

解决方案:

方案1:使用单一滚动容器(推荐)scrollerlist 合并,只使用 list 组件,通过设置 scroll-directionhorizontal 实现横向滚动:

<list scroll-direction="horizontal" 
      :show-scrollbar="false" 
      class="data-container"
      :bounce="false"
      :style="{width: '750rpx', height: height+'px'}">
    <header :style="{width: `${data.length*132}rpx`}">
        <!-- 表头内容 -->
    </header>
    <cell v-for="(item,index) in list" :key="index" 
          :style="{width: `${data.length*132}rpx`}">
        <!-- 行内容 -->
    </cell>
</list>

方案2:调整布局结构 如果确实需要嵌套,可以尝试以下调整:

<scroller scroll-direction="horizontal" 
          bounce="false"
          class="data-container"
          :style="{height: height+'px'}">
    <view :style="{width: `${data.length*132}rpx`}">
        <list :show-scrollbar="false" 
              class="room-state-x" 
              :bounce="false"
              :style="{height: height+'px'}">
            <!-- list内容 -->
        </list>
    </view>
</scroller>
回到顶部