Vue.JS on change event


Vue.JS on change event– It is very simple to add onchange event on any input element.


Vue.JS on change event Example

You can use watch for on change event here is simple example-

Html Part

Vue Js On Change Example:

<div id="app">
    {{ message }}
    <span>{{myVal}}</span><br />
    <input v-model="myVal">
</div>

JS Part

Vue Js On Change Example:

new Vue({
    el: '#app',
    data: {
        message: 'On change event example',
        myValue: 50
    },
    watch: {
        'myValue': function(val, preVal){
        if (val < 50) {
            this.message= 'Value is less than 50';
        }else{
          this.message= 'Value is greater than 50';
        }
      }
    }
})

Advertisements

Add Comment

📖 Read More