【发布时间】:2019-02-27 10:39:54
【问题描述】:
我正在尝试捕获@nuxtjs/auth 的错误响应,但它似乎除了未定义之外没有返回任何内容。
如果我包含用户,它会拒绝登录,所以我想知道它为什么返回 undefined。
配置:
auth: {
strategies: {
local: {
endpoints: {
login: {
url: 'http://127.0.0.1:80/api/login',
method: 'post',
propertyName: 'token'
},
logout: false,
user: {
url: 'http://127.0.0.1:80/api/me',
method: 'get',
propertyName: undefined
}
},
tokenRequired: true,
tokenType: 'bearer',
}
},
plugins: [
'@/plugins/auth.js'
]
},
插件:
export default function ({ app }) {
app.$auth.onError((error, name, endpoint) => {
console.error(name, error)
});
}
查看功能: - handleSuccess 和 handleFailure 都返回 undefined。
login() {
this.toggleProcessing(0);
let payload = {
username: 'admin',
password: 'admin123'
}
let handleSuccess = response => {
console.log(response);
this.toggleProcessing(0);
}
let handleFailure = error => {
console.log(error);
this.toggleProcessing(0);
}
this.$auth.loginWith('local', { data: payload }).then(handleSuccess).catch(handleFailure);
},
【问题讨论】: