axios不会在NS VUEJS APP中获得调用失败

时间:2019-02-04 19:01:13

标签: vue.js axios nativescript nativescript-vue

我有一种方法,可以在单击按钮时调用登录端点

pod update

无论我将其设置为url路线如何,axios都认为发布成功,并且总是注销成功消息和空白响应数据。

我使用该行直接在组件顶部导入axios

login() {
                let email = this.user.email
                let password = this.user.password
                axios.post('invalidRoute').then( (response) =>{
                    console.log('success')
                    console.log(response.data)
                }).catch(function (error) {
                    console.log('error')
                    console.log(error)
                })
            },

我在其他地方都没有使用它。

这是在基本的nativescript vue js应用程序中。

这是我的main.js的样子

import axios from 'axios'

这让我发疯,我不明白为什么它不会触发陷阱。

2 个答案:

答案 0 :(得分:0)

我认为这是Axios的问题。使用{N}时,如果请求失败,状态码将为null,当状态码具有虚假值时,Axios认为该请求成功。

好像在他们的Github中记录了类似的issue

答案 1 :(得分:0)

我发现axios或http在某些情况下都不会调用任何东西。 我不知道为什么,为此我做了两天的调查。没有线索。 只是改用Fetch,现在一切正常。