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>
相关推荐
Wetoria4 分钟前
管理 git 分支时,用 merge 还是 rebase?
前端·git
前端开发与ui设计的老司机14 分钟前
UI前端与数字孪生融合新领域:智慧环保的污染源监测与治理
前端·ui
一只小风华~27 分钟前
Web前端开发: :has功能性伪类选择器
前端·html·html5·web
Mr_Mao4 小时前
Naive Ultra:中后台 Naive UI 增强组件库
前端
前端小趴菜056 小时前
React-React.memo-props比较机制
前端·javascript·react.js
摸鱼仙人~7 小时前
styled-components:现代React样式解决方案
前端·react.js·前端框架
sasaraku.8 小时前
serviceWorker缓存资源
前端
RadiumAg9 小时前
记一道有趣的面试题
前端·javascript
yangzhi_emo9 小时前
ES6笔记2
开发语言·前端·javascript
yanlele9 小时前
我用爬虫抓取了 25 年 5 月掘金热门面试文章
前端·javascript·面试