[Vuejs]-How to detect response in VueJS?

1👍

You can do something like this to handle these cases:

submitRequest() {
  axios.post('/api/test', this.testData)
    .then(response => {
      // handle success
    })
    .catch(function(error) {
      // handle error
      if (error.response) {
        // The request was made and the server responded with a status code
      } else if (error.request) {
        // YOU CAN HANDLE IT HERE
        // The request was made but no response was received
        // `error.request` is an instance of XMLHttpRequest in the browser
        console.log(error.request);
      } else {
        // Something happened in setting up the request that triggered an Error
      }
    });
}

Leave a comment