Vue.js - event handling with on-mouse-click down (and not up)

Ben picture Ben · Feb 6, 2017 · Viewed 37.6k times · Source

With Vue.js 2 when I add in an @click event to an element and attempt to click something, the event isn't triggered until after I have completed my click (press down -> up).

How do I trigger an event immediate after a mouse click down?

Example:

<div @click="foo()">
    Hello
</div>

Answer

Saurabh picture Saurabh · Feb 6, 2017

You can simply use @mousedown event on the element, just like @click, to handle the mousedown event.

<button @mousedown="mouseDown">
   mouseDown 
</button>

See working fiddle: https://fiddle.jshell.net/mimani/feL03wgd/