Search code examples
vue.js

How to unset focus on an input after keyup.enter event in Vuejs?


How to unset input focus after keyup.enter event ?

<v-text-field v-on:keyup.enter="onPageChange"></v-text-field>

My goal to prevent the suggestions popup which hides a table behind.


Solution

  • To unset focus on input after keyup.enter the event, first pass the $event object to the function like:

    <v-text-field v-on:keyup.enter="onPageChange($event)">
    </v-text-field>
    

    Then in the onPageChange() method call blur() method based on the event target like:

    onPageChange(event){
       // Your rest of the code here..
    
       // finally call blur() like:
       event.target.blur(); 
    }