小程序uview actionSheet 内容过多高度设置
问题:u-action-sheet滚动不了
<u-action-sheet :list="list" v-model="show" @click="xxx"></u-action-sheet>
使用uview ui :u-action-sheet, 但是item太多,超出屏幕没法滚动, 去查官方文档的时候发现并没有设置滚动的属性
官方文档:ActionSheet 操作菜单 | uView 2.0 - 全面兼容 nvue 的 uni-app 生态框架 - uni-app UI 框架
解决办法:
第一步:修改源码
我这里用的HB转译的小程序,路径如下
找到node_modules -> uview_ui -> components -> u-action-sheet -> u-action-sheet.vue
<template><u-popup mode="bottom" :border-radius="borderRadius" :popup="false" v-model="value" :maskCloseAble="maskCloseAble"length="auto" :safeAreaInsetBottom="safeAreaInsetBottom" @close="popupClose" :z-index="uZIndex"><view class="u-tips u-border-bottom" v-if="tips.text" :style="[tipsStyle]">{{tips.text}}</view><!-- 增加个循环在block外层 --><scroll-view scroll-y style="min-height: 100rpx;max-height: 700rpx;"><block v-for="(item, index) in list" :key="index"><view@touchmove.stop.prevent@tap="itemClick(index)":style="[itemStyle(index)]"class="u-action-sheet-item u-line-1":class="[index < list.length - 1 ? 'u-border-bottom' : '']":hover-stay-time="150"><text>{{item.text}}</text><text class="u-action-sheet-item__subtext u-line-1" v-if="item.subText">{{item.subText}}</text></view></block></scroll-view><view class="u-gab" v-if="cancelBtn"></view><view @touchmove.stop.prevent class="u-actionsheet-cancel u-action-sheet-item" hover-class="u-hover-class":hover-stay-time="150" v-if="cancelBtn" @tap="close">{{cancelText}}</view></u-popup>
</template>
这个时候在电脑上是可以滚动的,但是手机不行
第二步:删除禁用触摸事件
还是源码的位置,可以看到block包裹的view有一个@touchmove.stop.prevent,这个是禁止触摸事件的,就是因为它导致的手机没法滚动,把这个删掉即可
<template><u-popup mode="bottom" :border-radius="borderRadius" :popup="false" v-model="value" :maskCloseAble="maskCloseAble"length="auto" :safeAreaInsetBottom="safeAreaInsetBottom" @close="popupClose" :z-index="uZIndex"><view class="u-tips u-border-bottom" v-if="tips.text" :style="[tipsStyle]">{{tips.text}}</view><!-- 增加个循环在block外层 --><scroll-view scroll-y style="min-height: 100rpx;max-height: 700rpx;"><block v-for="(item, index) in list" :key="index"><!-- @touchmove.stop.prevent --><view@tap="itemClick(index)":style="[itemStyle(index)]"class="u-action-sheet-item u-line-1":class="[index < list.length - 1 ? 'u-border-bottom' : '']":hover-stay-time="150"><text>{{item.text}}</text><text class="u-action-sheet-item__subtext u-line-1" v-if="item.subText">{{item.subText}}</text></view></block></scroll-view><view class="u-gab" v-if="cancelBtn"></view><view @touchmove.stop.prevent class="u-actionsheet-cancel u-action-sheet-item" hover-class="u-hover-class":hover-stay-time="150" v-if="cancelBtn" @tap="close">{{cancelText}}</view></u-popup>
</template>
vue页面
<u-action-sheet :list="list" v-model="show" @click="xxxx"></u-action-sheet>
<!-- 在data里定义list数组对象 -->
这样就可以了