Linu P M
Linu P M

Reputation: 31

Which event is triggered when v model value is changing

I'm new to Vuejs and my requirement is to write a single functional globally to trigger whenever v-model value of my form elements are set. I tried to write this for element.onchnage but this is not working.

Can some one tell me which HTML event is triggered when the v-model value is set in vuejs ?

Upvotes: 3

Views: 3570

Answers (1)

Bergur
Bergur

Reputation: 4067

Hey Linu and welcome to SO.

Check out the docs for Form input bindings: https://v2.vuejs.org/v2/guide/forms.html

There it says:

v-model internally uses different properties and emits different events for different input elements:

  • text and textarea elements use value property and input event
  • checkboxes and radiobuttons use checked property and change event;
  • select fields use value as a prop and change as an event.

So instead of v-model you can do the following for inputs

<input :value="dataProperty" @input="dataProperty = $event.target.value" />

Upvotes: 3

Related Questions