vue 有弹层时,实现页面不滚动
2019-03-06 本文已影响0人
AAA前端
项目里有个全屏的弹窗,然后弹窗下面手指滑动,页面仍然在滚动。 解决代码如下:
</template>
<script>
var preD = function(e) {
e.preventDefault();
};
export default {
props: ["active"],
watch: {
active(flag) {
if (flag) {
document.body.style.overflow = "hidden";
document.addEventListener("touchmove", preD, { passive: false }); //禁止页面滑动
} else {
document.body.style.overflow = ""; //出现滚动条
document.removeEventListener("touchmove", preD, { passive: false });
}
}
}
};
</script>
<style lang="scss" scoped>