将如下方法绑定在弹窗组件最外层盒子上
<view class="modal-container" @touchmove.stop.prevent="handleTouchMove"></view>
methods: {
// 解决弹窗滚动穿透问题
handleTouchMove(e) {
e.stopPropagation();
}
}
注意:该方法仅适用于弹窗中内容不需要滚动的情况,因为加上这个会导致弹窗中的内容也会无法滚动
如果弹窗中内容有滚动条,要解决弹窗穿透可在弹窗弹出的时候将父元素页面设置overflow: hidden,代码如下:
<view :class="['index-page', showPopup ? 'fixed-page' : '']">
<!-- 此处代码省略...... -->
<!-- 弹窗组件 -->
<custom-popup :show="showPopup" />
</view>
.fixed-page {
height: 100vh !important;
overflow: hidden !important;
}