VUE中,在一个页面打开弹框,在弹框中上下滑动,下方页面会跟着滑动。
解决办法有2种,第2种方法比较简单
方法一:
在main.js中加入代码:
//弹出框禁止滑动
Vue.prototype.noScroll = function () {
var mo = function (e) { e.preventDefault() }
document.body.style.overflow = 'hidden'
document.addEventListener('touchmove', mo, false)// 禁止页面滑动
}
//弹出框可以滑动
Vue.prototype.canScroll = function () {
var mo = function (e) {
e.preventDefault()
}
document.body.style.overflow = ''// 出现滚动条
document.removeEventListener('touchmove', mo, false)
}
在打开弹框的地方调用
//禁止下层页面滑动
this.noScroll()
关闭弹框时,调用:
this.canScroll()
完整代码:
在弹框之前,禁止页面滑动:
//禁止下层页面滑动
this.noScroll()
this.$refs.listDialog.show(this.showList, '能量列表', {
type: 'alert',