1

对于身份验证,我使用vue-auth@^3.2.0-betaaxios HTTP 驱动程序。axios 本身在 0.19.2 上。

示例代码

this.$auth.login({ data: body, redirect: false }).then(
() => {
    // Do success stuff...
},
e => {
    this.error = true
    if (e.response.status === HttpStatus.UNAUTHORIZED) {
      this.loginFailed++;
    }
});

如果用户提供的凭据无效,服务器会以 401 响应并显示错误消息。这是正常工作的。

但是,在检查控制台时,我会看到以下错误消息。它似乎没有任何“功能后果”,但我想知道为什么会抛出这个错误。虽然我知道肯定有一些未兑现的承诺,但我不知道那可能在哪里。

Uncaught (in promise) Error: Request failed with status code 401
    createError createError.js:16
    settle settle.js:17
    handleLoad xhr.js:61
    dispatchXhrRequest xhr.js:36
    xhrAdapter xhr.js:12
    dispatchRequest dispatchRequest.js:52
    promise callback*request Axios.js:61
    wrap bind.js:9
    node_modules axios.1.x.js:51
    node_modules vue-auth.esm.js:819
    node_modules vue-auth.esm.js:818
    node_modules Login.vue?vue&type=script&lang=js&:149
    VueJS 4
    method backend.js:1793
    node_modules UAForm.vue?vue&type=script&lang=js&:12
    submit UAForm.vue:13
    VueJS 33
createError.js:16

4

1 回答 1

0

我认为问题在于使用axios!您的代码中没有任何问题。

我认为您的代码应该包含如下所示的 catch

login () {
      this.$auth.login({
        data: this.data,
      })
        .then((res) => {    
         ....
        })
        .catch((err) => {
         .....    
        })
      }
于 2020-08-07T13:54:48.647 回答