N
N
Nikolai Chuprik2019-02-08 22:11:57
Vue.js
Nikolai Chuprik, 2019-02-08 22:11:57

How to refer to input value?

<input @change = "doSomethingWithValue( this.value )" />   //  Так не работает
<input @change = "doSomethingWithValue(" + this.value + ")" >   //  ...и так тоже

The code above is not working, but I hope it reflects the meaning: do I need to pass the value of the input field to the Vue method? I understand that:
1. You can make this field reactive by linking it to a variable in Vue.
2. You can access the field via document.getElement... and so on.
Is it possible to do this somehow easier than in paragraphs. 1 and 2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-02-08
@choupa

<input @change="doSomethingWithValue" />

methods: {
  doSomethingWithValue(e) {
    const value = e.target.value;
    ...

If you need to pass some additional parameters to the method, then the event object is available in the template as $event:
<input @change="doSomethingWithValue($event, 'hello, world!!')" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question