reactjs - 登录并传递电子邮件地址后,如何使用字符串参数调用 GET api,以便数据出来?(反应.js)
问题描述
我需要在登录后调用带有字符串参数的 GET api,因此将显示用户详细信息。我做的api是带有电子邮件字符串参数的GET API。
我需要使用电子邮件的路径变量调用 api 以获取详细信息。
class Home extends Component {
constructor(props){
super(props);
this.state ={
loginEmail: this.props.location.state.loginEmail,
isLoaded: false,
redirect: false
}
this.logout = this.logout.bind(this);
}
componentDidMount(){
fetch('https://ems-unimas-58134.herokuapp.com/api/users/view/${email}')
.then(res => res.json())
.then(json => {
this.state({
isLoaded: true,
})
});
}
我不确定这是否是我在 componentDidMount 中的正确方式。顺便问一下,有没有其他方法可以在我登录主页后自动调用api。
解决方案
其他方式可以是……您可以在登录 api 成功响应后调用此 api。我是说
fetch('url to login').then(res => res.json())
.then(json => {
fetch('https://ems-unimas-58134.herokuapp.com/api/users/view/${email}')....
)
推荐阅读
- node.js - 上传图片,然后使用 Multer 和 Express.js 进行更新
- ram - 为什么 RAM 在 O(1) 时间内访问任何内存地址?
- asynchronous - d3.json 异步解决方案
- python - 如何使用熊猫在特定列中写入
- php - Laravel PHP - 在选择列表中选择 db 中的 set 选项
- javascript - React - 从功能更改路线
- php - 仅针对某些用户和设备的 PHP 会话丢失
- asp.net - Azure AD 不记名令牌 - 获取用户标识符
- phpstorm - 使用代码编辑器更改文件时出现错误的意外标记:“”(第 1 列,代码点 U+0000)
- amazon-web-services - AWS Lambda 将图像写入 S3 访问被拒绝