尝试使用"then"承诺时无法读取未定义的属性(读取"then")



我目前正在使用reactjs构建一个登录页面。登录页面获取用户详细信息并将其传递给API对象,该对象具有授权用户详细信息的授权功能。在登录组件中,在获得详细信息后,我会调用授权函数,它看起来像这样:

const api = new API();
api.authorise(email, password, appid).then((result) => {
if (result.status === 200) {
console.log("Auth Successful");
return result;
} else {
console.log("Auth Failed")
return result;
}
});

然而,当这个调用运行时,它成功地到达了"authorize"函数,但给出了一个"Uncaught TypeError:无法读取未定义的属性(读取"then"(,我很难弄清楚原因。授权功能如下所示(使用Axios发送请求(:

authorise(email, password, appid) {
this.email = email;
this.password = password;
this.appid = appid;
let url = "api url";
const data = {
"data1": email,
"data2": password,
"data3": appid
}
axios.post(url, data).then((res) => {
return res;
}).catch((err) => {
return err;
})
}

我已经尝试将authorize函数声明为:authorise = (email, password, appid) => {},但没有成功。任何关于如何停止这一错误或重组承诺电话的建议都将不胜感激。提前谢谢。

您忘记了退货承诺。。

authorise(email, password, appid) {
this.email = email;
this.password = password;
this.appid = appid;
let url = "api url";
const data = {
"data1": email,
"data2": password,
"data3": appid
}
return axios.post(url, data)
}

相关内容

最新更新