在vue 中 使用 mint-ui 的 Picker 选择器 组件,在下滑或上滑和手机浏览器原生滑动事件有冲突(通常在 IOS 上 会有这个现象),可以监听 touchmove 事件,来阻止默认事件,具体看代码
参考 http://iscrolljs.com/ 这个网站
代码如下:
function isPassive () { var supportsPassiveOption = false try { addEventListener('test', null, Object.defineProperty({}, 'passive', { get: function () { supportsPassiveOption = true } })) } catch (e) {} return supportsPassiveOption }
function preventDefaultFunc (e) { e.preventDefault() }
export function preventTouchmove (onoff) { if (onoff) { document.body.addEventListener('touchmove', preventDefaultFunc, isPassive() ? { capture: false, passive: false } : false) } else { console.log('wawawwaawa') document.body.removeEventListener('touchmove', preventDefaultFunc, isPassive() ? { capture: false, passive: false } : false) } }
然后通过
import { preventTouchmove } from 'utils/common'
来导入这个方法,然后使用,onoff 是开关,来传 布尔值
preventTouchmove(true/false)