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>
相关推荐
百***359417 分钟前
如何在树莓派部署Nginx并实现无公网ip远程访问内网制作的web网站
前端·tcp/ip·nginx
花果山总钻风22 分钟前
Chrome 插件框架 Plasmo 基本使用示例
前端·chrome
资讯第一线24 分钟前
《Chrome》 [142.0.7444.60][绿色便携版] 下载
前端·chrome
会篮球的程序猿37 分钟前
原生表格文本过长展示问题,参考layui长文本,点击出现文本域
前端·javascript·layui
top_designer37 分钟前
Firefly 样式参考:AI 驱动的 UI 资产“无限”生成
前端·人工智能·ui·aigc·ux·设计师
蜗牛前端1 小时前
使用 Trae AI 开发完整的开源 npm 包:snail-git-add
前端
哆啦A梦15881 小时前
48 我的地址页面布局
javascript·vue.js·node.js
Dontla1 小时前
React useMemo(当依赖项未变化,重复渲染时直接返回上一次缓存计算结果,而非重新执行计算)
前端·react.js·缓存
阿斌_bingyu7091 小时前
uniapp实现android/IOS消息推送
android·ios·uni-app
花生Peadar1 小时前
AI编程从入门到精通
前端·后端·代码规范