vue弹层时禁止页面滚动

创建组件时禁止页面滚动:

created(){
    //禁止页面滑动
    document.body.addEventListener('touchmove', this.bodyScroll, { passive: false }); 
},

组件销毁时解除禁止:

destroyed(){
    // 解绑禁止页面滚动事件
    document.body.removeEventListener('touchmove', this.bodyScroll, { passive: false });
}

 bodyScroll方法:

bodyScroll(event){
    event.preventDefault();  
}

 

posted @ 2019-07-30 14:50  seeBetter  阅读(2054)  评论(0编辑  收藏  举报