Vue 滚动事件穿透解决方案
2020-08-30 本文已影响0人
小贤笔记
移动端
- 阻止默认事件
<div class="test" @touchmove.prevent></div>
PC
// 停止页面滚动
stopMove() {
let m = function(e) {
e.preventDefault();
};
document.body.style.overflow = 'hidden';
document.addEventListener('touchmove', m, { passive: false });
},
// 开启页面滚动
canMove() {
let m = function(e) {
e.preventDefault();
};
document.body.style.overflow = '';
document.removeEventListener('touchmove', m, { passive: true });
}