Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

How to detect enter key in vue?

Hi all, I wonder if there is a better way to detect the enter key in vue please:

 <input id="field1" type="text" v-on:keyup="keymonitor">


        keymonitor: function(event) {
        console.log(event.key);
       if(event.key == "Enter")
       {
         console.log("enter key was pressed!");
       }

I tried keyup.enter but this starts my search when the key is released which is incorrect. I only need my search to start if the enter key is tapped, not on every key up.

Any idea please?

Thanks.

0 likes
4 replies
Sinnbeck's avatar

Does what your are doing there not work?

Personally I prefer keycodes

function(event) {
       if(event.keyCode === 13)
       {
         console.log("enter key was pressed!");
       }
LaraBABA's avatar

Keycode are now deprecated in vue 3. This is why I prefer not to use them on/keycode-modifiers.html#_2-x-syntax

Please or to participate in this conversation.