[Vuejs]-Global catch for submit forms in Vue.js 2.0

0๐Ÿ‘

.then() and .catch() are both functions, so I would just create a new method with your repetitive code. Something like:

methods: {
  save () {
    var self = this
    return this.saveEvent(payload)
      .then(() => { self.resetForm() })
      .catch(resp => { 
        if (resp.status === 400) {
          self.repetitiveTask()
        }
      })
  },
  repetitiveTask () {
    // verry repetitive task!!
  }
}

I did var self = this so you can call the repetitiveTask() method in a different scope.

Leave a comment