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

40 篇文章 1 订阅

*1、问题所在:

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

2、要求:

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

3、实现思路:

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

4、代码如下:

        这里我封装成了组件弹窗

<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>

  • 12
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
uni-popupuni-app 中的弹窗组件,可以用来展示一些提示信息或作为选择器等功能的弹窗。下面是 uni-popup使用方法: 1. 引入组件:在需要使用页面中,引入 uni-popup 组件。 ``` <template> <view> <uni-popup></uni-popup> </view> </template> <script> import uniPopup from '@/components/uni-popup/uni-popup.vue' export default { components: { uniPopup } } </script> ``` 2. 基本使用:在页面使用 uni-popup 组件时,需要传递一些参数,如弹窗内容、弹窗位置、是否显示遮罩等。 ``` <template> <view> <uni-popup :show="showPopup" :position="position" :mask="mask" @change="popupChange" > <view>这是弹窗的内容</view> </uni-popup> </view> </template> <script> export default { data() { return { showPopup: false, // 是否显示弹窗 position: 'bottom', // 弹窗位置,可选值为 top、bottom、center mask: true // 是否显示遮罩 } }, methods: { // 弹窗状态改变时触发 popupChange(e) { console.log(e) } } } </script> ``` 3. 高级使用:可以通过 slot 传递自定义的弹窗内容,并在弹窗状态改变时触发相应的事件。 ``` <template> <view> <uni-popup :show="showPopup" :position="position" :mask="mask" @change="popupChange" > <view slot="content">这是自定义的弹窗内容</view> <view slot="footer"> <button @click="confirm">确定</button> <button @click="cancel">取消</button> </view> </uni-popup> </view> </template> <script> export default { data() { return { showPopup: false, position: 'bottom', mask: true } }, methods: { popupChange(e) { console.log(e) }, confirm() { this.showPopup = false console.log('点击了确定按钮') }, cancel() { this.showPopup = false console.log('点击了取消按钮') } } } </script> ``` 以上是 uni-popup 的基本使用方法,可以根据实际需求进行相应的调整和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱池鱼的酱酱仔

您的鼓励是我前进的动力哦~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值