Vue 禁止滚动

比如我们想做一个校验,会出现一个弹窗,填写校验信息,此时页面禁止滚动

可以绑定如下事件

change(){
   // show 控制弹窗显隐
this.show = !this.show if(this.show){
// pc 端直接删掉滚动条 document.body.style.overflow
= "hidden" // 移动端禁止 touchmove 默认事件,上下滑
     document.addEventListener(
"touchmove", (e) => { e.preventDefault() }) }else{ document.body.style.overflow = "" document.removeEventListener("touchmove", (e) => { e.preventDefault() }) } }

posted @ 2022-12-26 12:49  邢韬  阅读(752)  评论(0编辑  收藏  举报