uniapp 禁止遮罩层下的页面滚动

使用 @touchmove.stop.prevent="toMoveHandle" 事件修饰符

若需要禁止蒙版下的页面滚动,可使用 @touchmove.stop.prevent="moveHandle",moveHandle 可以用来处理 touchmove 的事件,也可以是一个空函数。将这个方法直接丢到弹窗的最外层 view 就好了,虽然在编译器上的滚轮依旧可以滚动,但真机环境下的手指滑动无法再触发。

为兼容各端,事件需使用 @ 的方式绑定,请勿使用小程序端的 bind 和 catch 进行事件绑定;也不能在 JS 中使用 event.preventDefault() 和 event.stopPropagation() 方法。

注意:如果使用 uview 之类的 ui 框架,@touchmove.stop.prevent 必须放在底层的 view 上面。由于大部分的 ui 框架结构复杂,很容易不生效,建议自己写一个遮罩层再加上这个事件,这样的话就能正常生效了。

<!-- 弹窗 -->
<view class="pop-box" @touchmove.stop.prevent="toMoveHandle">
    
</view>
toMoveHandle() {},

更多可参考:介绍 | uni-app官网

猜你喜欢

转载自blog.csdn.net/AdminGuan/article/details/132460869