[Vuejs]-How to validate a condition when a status changes in vuejs

2👍

Inside your @click directive that is calling the method update()… You should consider moving the validateSuccess as a callback so it will fire after the success or failure of the update method call.

@click.prevent="update()"

methods: {
 update() {
   Spark.put(…).then(r=>{
    // is successful 
    this.validateSuccess()
   }).catch(e=>{
    // is failure
    this.validateSuccess()
   });
 },

 validateSuccess() {
   console.log('no-in-condition')
   if (this.form.successful) {
     console.log('in-condition');
   } 
 },
},

This is assuming the Spark.put has a promise that it returns

👤jremi

Leave a comment