19

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

3 Answers 3

41

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I have been on the documentation page. But because there is no concrete example, it's easy to read "over" it.
1

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

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

Comments

0
<input type="text" class="search-bg" placeholder="Search" v-model="search" @keyup="searchData"/>

1 Comment

thank you for the contribution -- can you add an explanation of what your code does to help future readers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.