[Vuejs]-How to check v-model empty and display error before submit

0👍

could be any of this.
v-on:submit.prevent="onSubmit"
v-on:click.prevent="select(kudo.id)"

I don’t know where are you submitting but check this events if you want to know more.

0👍

In your methods, add a form verification method:

checkForm: function (e) {
  if (this.name && this.age) { //change these to your required field names
    this.addKudoPost(this.authuser);
  }

  this.errors = [];

  if (!this.name) { //change these to your required field names
    this.errors.push('Name required.');
  }
  if (!this.age) { //change these to your required field names
    this.errors.push('Age required.');
  }

  e.preventDefault();
}

Leave a comment