I am using Vue.js in my app and have a text input within a form
The submit is always fired on keydown. So use keydown instead of keyup.
<input type="text" v-on="keydown:addCategory | key 'enter'">
Here's a solution for Vue.js 2.x:
<input type='text' v-on:keydown.enter.prevent='addCategory' />
This works
<input type="text" class="form-control" v-model="get_user" @keydown.enter.prevent = "">
why dont just disable the form submission ?
<form v-on:submit.prevent><input .../></form>
You can get event from the HTML and send it to Vue just to preventDefault like so:
HTML
<input type="text" v-on:keydown.13="my_method($event)">
JS
methods: {
my_method(event){
// do something
if (event) event.preventDefault();
if (event) event.stopPropagation();
},
},
I had an edge case where an input was within a popup, and the popup was for only part of the form. I wanted to prevent enter from submitting the form while the popup was open, but not altogether. This worked:
<input type="text" @keydown.enter.prevent = "" />