uview ui 1.x ActonSheet项太多,设置滚动(亲测有效)

问题:ActionSheet滚动不了。

使用uview ui :u-action-sheet, 但是item太多,超出屏幕了, 查了一下文档,并没有设置滚动的地方。

官方文档:ActionSheet 操作菜单 | uView - 多平台快速开发的UI框架 - uni-app UI框架

解决

只能修改源码了,在v-for遍历外面添加一个滚动视图,即可,其他不变

复制代码
<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>
    <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>

效果:控制差不多半屏显示了,不超屏幕了。 在电脑上用鼠标滚轮很正常。但是在手机滚动不了。

问题2: 手机上触摸滚动不了。

再去看源码,发现包裹着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>
    <scroll-view scroll-y="true" style="min-height: 100rpx;max-height: 700rpx;">
		<block v-for="(item, index) in list" :key="index">
			<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

复制代码
//...
<view class="submenu">
      <u-action-sheet :list="subList" v-model="showSub" :tips="menuTitle" @click="selectSubMenu"></u-action-sheet>
    </view>

//...


export default {
  components: {
    HeadNavBar
  },
  data() {
    return {
      menuTitle: {text: "运营管理"},
      subList: [{text: 'item1'}, {text: 'item2'}, {text: 'item3'}, {text: 'item4'}, {text: 'item5'},
        {text: 'item6'}, {text: 'item7'},{text: 'item8'}, {text: 'item9'},{text: 'item10'}, {text: 'item11'},{text: 'item12'}, {text: 'item13'}],
      showSub: false,}}
}

//...

手机上效果:

相关推荐
八月林城11 小时前
echarts在uniapp中使用安卓真机运行时无法显示的问题
android·uni-app·echarts
哈贝#11 小时前
vue和uniapp聊天页面右侧滚动条自动到底部
javascript·vue.js·uni-app
iOS阿玮13 小时前
苹果2024透明报告看似更加严格的背后是利好!
uni-app·app·apple
邹荣乐16 小时前
微信小程序动态tabBar实现:基于自定义组件,灵活支持不同用户角色与超过5个tab自由组合
前端·微信小程序·uni-app
不吃糖葫芦317 小时前
App使用webview套壳引入h5(三)——解决打包为app后在安卓机可物理返回但是在苹果手机无法测滑返回的问题
uni-app·webview
半兽先生21 小时前
uniapp微信小程序视频实时流+pc端预览方案
微信小程序·uni-app·音视频
胡斌附体1 天前
uniapp路由跳转toolbar页面
小程序·uni-app·switch·路由·type·uview-ui
阿諪諪1 天前
在VSCode中开发一个uni-app项目
ide·vscode·uni-app
发现你走远了1 天前
『uniapp』把接口的内容下载为txt本地保存 / 读取本地保存的txt文件内容(详细图文注释)
开发语言·javascript·uni-app·持久化保存
lqj_本人1 天前
鸿蒙OS&UniApp结合机器学习打造智能图像分类应用:HarmonyOS实践指南#三方框架 #Uniapp
机器学习·uni-app·harmonyos