uniapp使用u-popup组件弹窗出现页面还可滑动

*1、问题所在:

弹窗遮罩层出现了页面依旧可以上下滑动

2、要求:

为了用户更好交互体验,弹窗出现后应禁止页面往下滑动

3、实现思路:

在弹窗盒子外层添加个阻止触摸冒泡事件,使用@touchmove.stop.prevent

4、代码如下:

这里我封装成了组件弹窗

javascript 复制代码
<template>
	<view class="popup" @touchmove.stop.prevent="prevent">
		<u-popup :show="detailShow" @close="$emit('closeDialog', false)" mode="center" :round="20" :safeAreaInsetBottom="false">
			<view class="popup-box">
				<view class="popup-box-top">
					<image :src="popupExtraData.popupPic" mode="aspectFill">
					</image>
				</view>
				<view class="popup-box-section">
					<view class="section-teatil margin-top-sm flex justify-center text-xl text-bold">{{popupExtraData.popupTitle}}
					</view>
					<view class="section-inner" v-for="(item,index) in popupDataList" :key="item.name">
						<view class="flex align-center margin-left-sm text-df">
							<view class="inner-name margin-top-sm margin-right-xs name-text">{{item.name}}:</view>
							<view class="inner-name margin-top-sm  content-text">
								{{item.content?item.content:item.nullContent}}</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		props: {
			popupExtraData: { //传递额外的样式参数信息
				type: Object,
				default: function() {
					return {};
				},
			},
			popupDataList: { //传递数据列表信息
				type: Array,
				default: function() {
					return [];
				}
			},
			popupShow: { //传递弹窗是否显示
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				detailShow: false
			};
		},
		methods:{
			prevent(e){}//弹窗弹起禁止页面滑动
		},
		watch: {
			popupShow: {
				handler: function(newVal) {
					this.detailShow = newVal
				},
				deep: false, // 深度监听
				immediate: false // 立即执行
			}
		},
	}
</script>
相关推荐
对空六课16 分钟前
支持注意力分析的热力图工具有哪些?
前端·数据库·数据分析
Csvn1 小时前
Vue3 响应式与编译:依赖收集如何升级为节点级靶向更新
前端
星栈2 小时前
pnpm 12 升级实测
前端·javascript
Sirens.3 小时前
Java并发锁详解:六类锁策略与 synchronized 底层原理
java·前端·算法
特创数字科技4 小时前
一个纯本地运行的图片处理工具:压缩 / 裁剪 / 九宫格 / 圆角 / 滤镜 / 拼图 / 水印,终生使用
前端
IT_陈寒5 小时前
Vue的v-if和v-for混用居然是个天坑
前端·人工智能·后端
天衍四九-5 小时前
【无标题】
前端·spring boot·mysql·nginx·docker
广州华水科技5 小时前
2026年单北斗GNSS变形监测系统推荐榜单,解锁GNSS位移监测新高度
前端
xcyxiner5 小时前
DicomViewer24 修复编译bug(window test 失败)
前端·qt