/**
* 监听右滑手势
* @param {Function} callback 回调函数,手势完成后执行的操作
* @return {undefined} 无返回参数 [description]
*/
function bindGesture(callback) {
if (store.state.loginInfo.isIOS == 'true') {
let touchStartTaget;
// touchstart 触摸开始事件 touchend 触摸结束事件
document.ontouchstart = (evt) => {
startTouch(evt)
};
document.ontouchend = (evt) => {
endTouch(evt)
};
function startTouch(evt) {
// 缓存起始位置信息
touchStartTaget = evt.targetTouches[0]
}
function endTouch(evt) {
const endTouch = evt.changedTouches[0]
const startTouch = touchStartTaget
const deltaX = endTouch.clientX - startTouch.clientX
const deltaY = endTouch.clientY - startTouch.clientY
// 向右滑, x轴有效长应大于100px
if (deltaX > 100) {
// 上下偏移量小于45°
if (Math.abs(deltaY) / deltaX <= 1) {
// 认为 ”右滑动“
typeof callback == 'function' && callback()
}
}
}
}
}
Vue.prototype.$bindGesture = bindGesture;
mounted() {
this.$bindGesture(()=>{
this.$router.back()
});
},
*了解更多
【axios使用】Vue中 Vue.prototype 详解及使用_vue.prototype.$_流枫maplefoliage的博客-CSDN博客