在vue.js中的API请求中捕获错误

时间:2018-03-13 05:06:18

标签: vuejs2

我试图在

中发现错误
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)
                    }
            })

但我不能这样抓住。感谢。

1 个答案:

答案 0 :(得分:1)

看起来您正在使用vue-resource来发出ajax请求。我只使用过axios,但是看一下vue-resource的文档看起来像你的错误回调是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) } })

在您的代码中尝试此操作

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 3720347648 bytes for committing reserved memory.

以下是文档的链接:this page