search

Home  >  Q&A  >  body text

How to bind multiple clicks with different modifiers in vue?

<input v-on:click.ctrl="SelectedMultiple(item.id)" v-on:click="Selected(item.id)" />

如上  我想实现的是 按住ctrl的时候多选 
但是在触发SelectedMultiple之后会再次触发Selected事件
这个该如何解决呢?
巴扎黑巴扎黑2835 days ago609

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-05-19 10:46:42

    Each v-on will have an independent handler. When the event is triggered, it is placed in an array and executed sequentially.
    They will not affect each other. @click.ctrl cannot prevent the execution of @click.
    So it can only be executed in @click judges $event to filter out events where ctrl is pressed

    <input @click.ctrl="SelectedMultiple(item.id)" 
    @click="!$event.ctrlKey && Selected(item.id)" />

    reply
    0
  • 黄舟

    黄舟2017-05-19 10:46:42

    There should be a keyboard event

    reply
    0
  • Cancelreply