Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text field value onkeyup vue js

Without using v-model, how to retrieve text field's value when typing? If possible without using any methods.

<input type="text" class="form-field"
    v-on:keyup="data.sample = this.target.value">

I used

  • this.value
  • this.target.value

  • e.target.value

like image 671
Wesley Brian Lachenal Avatar asked Jul 17 '16 16:07

Wesley Brian Lachenal


People also ask

How do I get text from input Vue?

To get an input value in Vue, we can use the v-model directive to set up a two-way binding between the value and a variable. Every time the user changes the text in the input field, the text variable will be updated automatically. We can then use this variable to perform an action or display information.

How do I use Onkeyup in VUE JS?

The v-on:keyup directive is a Vue. js directive used to add an event listener to an button in the keyboard. First, we will create a div element with id as app and let's apply the v-on:keyup directive to the input element. Further, we can execute a function when we press the associated key.

What does Onkeyup do in Javascript?

Definition and Usage The onkeyup attribute fires when the user releases a key (on the keyboard). Tip: The order of events related to the onkeyup event: onkeydown. onkeypress.

What is Keyup enter in angular?

(keyup) is an Angular event binding to respond to any DOM event. It is a synchronous event that is triggered as the user is interacting with the text-based input controls. When a user presses and releases a key, the (keyup) event occurs.


2 Answers

The solution is:

<input type="text" v-on:keyup="this.$data.name = $event.target.value">

From documentation:

When listening to native DOM events, the method receives the native event as the only argument. If using inline statement, the statement has access to the special $event property: v-on:click="handle('ok', $event)"

jsfiddle

like image 79
Andrey Etumyan Avatar answered Oct 29 '22 11:10

Andrey Etumyan


The best way to handle any key with Vuejs is like this :

<input type="text" @keyup.stop.native="handleInput($event)">

like image 1
Biya Paul Avatar answered Oct 29 '22 09:10

Biya Paul