Vuejs & Axios: Module de commentaires

Par kndeye, il y a 9 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

voila le code

sendComment: function () { this.loading = true this.addComment({ ........... ............ .......... }).catch((response) => { console.log(response.data) this.error = response.data }).then(() => { ........... }) }

Le problème

Et le problème c'est que il n'y a rien dans response.data, j'ai vérifié avec l'inspecteur de Chrome dans l'onglet Network et il me renvoi bien les erreurs au format json mais, je l'obtients pas dans le catch, je sais pas si ça vient d' axios ou vuejs.
Si vous avez des idées !!!??

3 réponses

Grafikart, il y a 9 ans

Et response contient quoi ?

kndeye, il y a 9 ans

Quand je debug response ça donne ça

Error: Request failed with status code 422 at createError (eval at <anonymous> (http://localhost:8080/app.js:660:2), <anonymous>:15:15) at settle (eval at <anonymous> (http://localhost:8080/app.js:768:2), <anonymous>:18:12) at XMLHttpRequest.handleLoad (eval at <anonymous> (http://localhost:8080/app.js:654:2), <anonymous>:75:7)

j'ai vraiment tout vérifié mais je sais toujours pas où ça calle

kndeye, il y a 9 ans

Après des heures de recherche et de test, je viens de voir la solution. Apparemment c'était axios, j'ai changé le catch

sendComment: function () { this.loading = true this.addComment({ ........... ............ .......... }).catch((error) => { this.errors = error.response.data }).then(() => { this.loading = false })