我真的需要帮助。我在 connection.js 中定义了一个函数,可以尝试从 login.jsx 中调用它,但是当我查看浏览器控制台时,它给了我 Uncaught (in promise) TypeError: Server.getSecurePhrase is not a function .任何人都可以让我知道我的代码有什么问题。谢谢。
登录.jsx
import Server from "../connection/connection";
const Login = () => {
const onSubmit = async (data) => {
console.log("data is",data)
Server.getSecurePhrase(data).then(securePhrase => {
setSecurePhrase(securePhrase)
})
}
}
这是在 connection.js
async getSecurePhrase(data) {
console.log("Connection: getSecurePhrase");
return axios
.post(
"url is here", data
)
.then(responseJson => {
console.log("res: ", responseJson);
return responseJson.data.security_phrase;
})
.catch(error => {
console.log("Res: ", error);
return "NULL";
});
}