vue2-hammer: Using both swipe.right and swipe.left on the same component won't work

Hello, thanks for this wrapper!

I was trying to set both v-hammer:swipe.left="onSwipeLeft" and v-hammer:swipe.right="onSwipeRight" with 2 different callbacks, but one of the two callbacks isn’t working.

Is this a bug or there is a better way to do this?

Thanks!

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 13
  • Comments: 18 (8 by maintainers)

Most upvoted comments

@Aterr , I solved this using v-hammer:swipe.horizontal="onSwipe" and then parsing evt.direction inside onSwipe i can call onSwipeRight and onSwipeLeft.

That’s not (of course) a fix, but it’s working for me, until a fix is released!

Thanks for notifying it. I’ll find some time to add this new feature, supporting more directions on just one line. Like v-hammer:swipe.left.right. Please look forward to next release.

For anyone who has the same problem, as @bsdfzzzy said, you can use:

onSwipe(event){ console.log(event.type); if (event.type == “swipeleft”) { insertYourFunction() } else { insertYourOtherFunction() } }

Yes the syntax changed a little since version 2. I suggest you use swipe.left.right now. @LukeCarlThompson

Thanks for the update!

Just tested with version 2.1.1 and getting some slightly different issues. I also tested with pan events.

Now if I have these events v-hammer:swipe.left=“onSwipeLeft” v-hammer:swipe.right=“onSwipeRight”

onSwipeRight fires only on a right swipe, but onSwipeLeft does not fire if i swipe left.

If i have these events v-hammer:pan.start=“onPanStart” v-hammer:pan=“onPan”

Then only the onPan event fires never the onPanStart.

If I reverse the order to v-hammer:pan=“onPan” v-hammer:pan.start=“onPanStart”

Then only onPanStart event fires and never onPan

However if I have v-hammer:pan.start=“onPanStart” v-hammer:swipe.right=“onSwipeRight”

Then both events fire at the expected time.

It seems that the issue is only when there are multiple events linked to the same gesture.

@kino90 Worked for me too! Thanks 👍