Sliding event

Touchstart The position where the finger starts to slide; Touchmove The position of the finger; Touchend where the finger leaves;

code

<div @touchstart='touchstart' @touchmove='touchmove'></div>
Copy the code
touchstart (e) {
  If you want to block click events, uncomment the next line of code
    // e.preventDefault()
     this.startX = e.touches[0].clientX
     this.startY = e.touches[0].clientY
   },
   touchmove (e) {
     // e.preventDefault()
     this.moveX = e.touches[0].clientX
     this.moveY = e.touches[0].clientY
     this.startX - this.moveX <= 0 ? console.log('You're sliding to the right.') : console.log('You're sliding left.')
     if (this.startX - this.moveX <= -100) { // Right slide trigger
    // do something}}Copy the code

This. StartX – this. MoveX can easily determine whether to swipe left or right. You can also set the sensitivity so that the difference between them doesn’t trigger until 100