Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

Prevent Swipe Examples #114

Open
Ethanhackett opened this issue Jan 22, 2018 · 0 comments
Open

Prevent Swipe Examples #114

Ethanhackett opened this issue Jan 22, 2018 · 0 comments

Comments

@Ethanhackett
Copy link

Ethanhackett commented Jan 22, 2018

Loving how awesome this plugin so +1 for awesomeness!

I was utilizing a couple of swipes one in a parent and one in a child but I want to prevent propagation of swiping. I don't know the best way to implement this and maybe it's worth adding into the docs in some way. This is how I was able to prevent propagation to child elements and components.

<v-touch v-on:swipe="swipe">
    <div>Swipe with me</div>
    <div ref="preventSwipe">Don't swipe with me!!!</div>
    <div>Swipe with me</div>
</v-touch>

Then in my methods I check whether the to prevent the swipe.

methods: {
      swipe: function(e) {
        let that = this;
        // Prevent propagation for swipes inside the content box
        var allowSwipe = true;
        _.forEach(e.srcEvent.path, function(item, index){
          if (item == that.$refs.preventSwipe) {
            allowSwipe = false;
          }
        });
        // Only continue if prevent swipe is false
        if (allowSwipe) {
          // Identify direction
          if(e.offsetDirection == 4) {
           bus.$emit('shift-item', 'previous');
          }
          if(e.offsetDirection == 2) {
            bus.$emit('shift-item', 'next');
          }
        }
      },
    }

This works but I imagine there is a much smoother way to do it which might be worth putting in the docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant