我正在 try catch
中的错误this.$http.post('http://127.0.0.1:8000/api/address/store',address_data,{headers: {'Authorization': 'Bearer ' + this.$auth.getToken()}}).then(response => {
if(response.status == 422) {
console.log('hello')
console.log(response)
}
})
但我不能用这种方式捕捉。谢谢。
最佳答案
看起来您正在使用 vue-resource 来发出 ajax 请求。我只使用过 axios,但看了一下 vue-resource 的文档,您的错误回调似乎是 .then()
this.$http.post('/someUrl', [body], [config]).then(successCallback, errorCallback);
this.$http.post('http://127.0.0.1:8000/api/address/store',address_data,
{headers: {'Authorization': 'Bearer ' + this.$auth.getToken()}})
.then(response => {
// success
}, response => {
//error
if(response.status == 422) {
console.log('hello')
console.log(response)
}
})
这是文档的链接:https://github.com/pagekit/vue-resource
https://stackoverflow.com/questions/49248656/