jerrybendy / vue-touch-events

Support simple touch events (tap / swipe / touch hold)
MIT License
537 stars 51 forks source link

Event will self trigger when element create dynamically #88

Closed Y-Theta closed 3 years ago

Y-Theta commented 3 years ago

I bind touch:tap on my list item and when item rendered, the tap event self triggers

<template>
  <div class="root flex-column">
    <dir-ser
      class="navigate"
      :path.sync="syncdirpath"
    ></dir-ser>
    <div
      class="list-root"
      ref="list"
    >
      <div class="flex-column">
        <div
          class="item"
          v-for="item in items"
          :key="item.name"
        >
          <div class="item-container flex-row">
            <div
              class="icon"
              :class="[itemicon(item),item.type.toString()]"
            >
            </div>
<!--.............................................................................................-->
            <div
              class="name"
              :title="item.name"
              v-touch:tap="itemclick(null,item)"
            >{{ item.name }}</div>
<!--.............................................................................................-->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 private itemclick(event: any, item: serverItem) {
    switch (item.type) {
      case FileType.file:
        this.cmd(item);
        break;
      case FileType.directory:
        this.cd(item.name);
        break;
      case FileType.link:
        break;
    }
  }
andorfermichael commented 3 years ago

@20154530 What was your solution to this?

jerrybendy commented 3 years ago

@andorfermichael See this https://github.com/jerrybendy/vue-touch-events#how-to-add-extra-parameters

RichardCr commented 3 years ago

Hi Jerry, Nice Library! Thanks for providing it to the community :) I have a usecase where I am using virtual scrolling, as well as intersection observers as sometimes I am dealing with 1000s of elements. These get dynamically created as you scroll around. This leads to a lot of misfires by v-touch when the elements are created. While I can probably filter the misfires out in a method, I assume isn't great for performance which is already quite stretched, is there any way to make this only trigger on a touch event?

jerrybendy commented 3 years ago

@RichardCr I'm not understand you very clearly. Do you mean the disableClick in configuration?

If not, you can open a new issue and give me some more details.