帖子
帖子
用户
博客
课程
显示全部楼层
286
帖子
2
勋章
7万+
Y币

[开发工具] avm 的scroll-view 在小程序端异常

[复制链接]
发表于 2021-11-26 15:53:43
scroll-view 的  scroll-y 属性设置为true 的时候 在小程序端 假如里面元素过多,滚动的不是scroll-view 而是整个页面
然后 当 scroll-x 的属性为 true 的时候,在小程序端,无法横向滚动


示例代码为 scroll-y ='true' 的时候, scroll-x ='true'的demo代码就暂时没有,大佬们自己测试一下


  1. <template>
  2.         <view class="page">
  3.                 <safe-area></safe-area>
  4.                 <view class="test1">
  5.                         <text>123123123</text>
  6.                         <text>123123123</text>
  7.                         <text>123123123</text>
  8.                         <text>123123123</text>
  9.                         <text>123123123</text>
  10.                 </view>
  11.                 <view class="test">
  12.                         <scroll-view class="" scroll-y="true">
  13.                                 <view v-for="(item,index) in list">
  14.                                         <text>{item}</text>
  15.                                 </view>
  16.                         </scroll-view>
  17.                 </view>
  18.         </view>
  19. </template>

  20. <script>
  21. export default {
  22.         name: 'test',
  23.         install() {

  24.         },
  25.         apiready() {//like created

  26.         },
  27.         data() {
  28.                 return {
  29.                         list: [1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 33, 55, 66, 77, 88, 1111, 2222,1, 1, 1, 1, 1, 1, 1, 1, 1, 33, 55, 66]
  30.                 }
  31.         },
  32.         methods: {
  33.                 test(index) {
  34.                         this.data.active = index;
  35.                 }
  36.         }
  37. }
  38. </script>

  39. <style>
  40. .test3 {
  41.         width: 100%;
  42.         height: 100%;
  43. }
  44. .test {
  45.         flex: 1;
  46. }
  47. .test1 {
  48.         width: 100%;
  49.         height: 300px;
  50.         background: #000;
  51. }
  52. .page {
  53.         width: 100%;
  54.         height: 100%;
  55.         background: #fff;
  56. }
  57. </style>
复制代码


380
帖子
4
勋章
6
Y币
已反馈给相关技术,有结果会回复。
10
帖子
1
勋章
5672
Y币
本帖最后由 杨永安 于 2021-11-30 10:15 编辑

这个不属于bug,是属于css相关设置问题。

不推荐主贴代码中,给 scroll-view 嵌套一个空的 view.test 。这样会让你的节点变得复杂,尽量使用简单的嵌套。

尝试以下改变:

1. 将 scroll-view 外层的 view 删掉,并且移植 test 类到 scroll-view 。

  1. <template>
  2.         <view class="page">
  3.                 <safe-area></safe-area>
  4.                 <view class="test1">
  5.                         <text>123123123</text>
  6.                         <text>123123123</text>
  7.                         <text>123123123</text>
  8.                         <text>123123123</text>
  9.                         <text>123123123</text>
  10.                 </view>
  11.                 <scroll-view class="test" scroll-y="true" >
  12.                         <view v-for="(item,index) in list">
  13.                                 <text>{item}</text>
  14.                         </view>
  15.                 </scroll-view>
  16.         </view>
  17. </template>
复制代码


2. 执意(或者不可避免)嵌套,充分理解 flex 布局的 flex-basis 机制:
  1. <template>
  2.         <view class="page">
  3.                 <safe-area></safe-area>
  4.                 <view class="test1">
  5.                         <text>123123123</text>
  6.                         <text>123123123</text>
  7.                         <text>123123123</text>
  8.                         <text>123123123</text>
  9.                         <text>123123123</text>
  10.                 </view>
  11.                 <view class="test">
  12.                         <scroll-view class="" scroll-y="true" style="flex:1 1 0;">
  13.                                 <view v-for="(item,index) in list">
  14.                                         <text>{item}</text>
  15.                                 </view>
  16.                         </scroll-view>
  17.                 </view>
  18.         </view>
  19. </template>
复制代码



PS: flex-basis 参考资料: https://**.**/post/6997802025614327838

您需要登录后才可以回帖 登录

本版积分规则