【发布时间】:2022-01-06 13:58:06
【问题描述】:
这是我的目标 .....值来自登录(可以是任何东西)-> 例如 电子邮件:'aaaa@gmail.com' 密码:'12345678'
我应该在“@”之前取用户名并将其作为用户名传递给 api。
export const loginUser = (values, history, setFieldError, setSubmitting) => {
console.log("values from login", values)
//here i take the email split value and take as user name
const username = values.email.split("@")[0]
console.log("user name", username)
//now i should pass the username as a name parametr to api
return () => {
axios.get('https://api.agify.io/?', values
).then((response) => {
//if res ok should redirect it
console.log("response", response)
// history.push("/user")
}).catch(error => console.error(error))
setSubmitting(false);
}
}
如果它可以帮助这里是我的链接 https://codesandbox.io/s/charming-jang-py0mu?file=/src/auth/actions/userActions.js
【问题讨论】:
-
如果你想向 API 发送数据,你不应该使用 GET 方法。可能您需要 POST 方法并将凭据作为正文发送。
标签: javascript reactjs api redux query-parameters