对于身份验证,我使用带有axios HTTP驱动程序的vue-auth@^3.2.0-beta。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发布于 2020-08-07 21:54:49
我认为问题出在使用axios上!在您的代码中没有捕获。
我认为你的代码应该像下面这样包含catch
login () {
this.$auth.login({
data: this.data,
})
.then((res) => {
....
})
.catch((err) => {
.....
})
}https://stackoverflow.com/questions/63299016
复制相似问题