addEventListener()与removeEventListener()可参考:https://blog.csdn.net/qq_29606781/article/details/67650869
// 监听滑动事件
let startPosition = {},
deltaY = 0,
endPosition = {};
document.addEventListener('touchstart', touchFunc, false);
document.addEventListener('touchmove', touchFunc, false);
document.addEventListener('touchend', touchFunc, false);
function touchFunc(e) {
let event = e || window.e;
let touch = {};
switch (event.type) {
case 'touchstart':
deltaY = 0;
touch = event.touches[0];
startPosition = {
x: touch.pageX,
y: touch.pageY
};
break;
case 'touchend':
console.log(deltaY); //根据滑动的距离 让轮播下一页
if (deltaY < -100 ) {
swipe.value.next();
isTouch.value = false;
}
break;
case 'touchmove':
touch = event.touches[0];
endPosition = {
x: touch.pageX,
y: touch.pageY
};
deltaY = endPosition.y - startPosition.y;
break;
}
}