【发布时间】:2020-09-16 00:22:57
【问题描述】:
我在代码的前端部分使用 React JS。我想将不记名令牌存储在 cookie 中,然后在成功调用 API 时在内容字段中返回不记名令牌。由于我之前没有使用过 cookie,所以想知道如何完成这项任务。后端部分也不是我做的。 以下是我调用 API 的代码
onSubmitSignup = () => {
fetch('https://cors-anywhere.herokuapp.com/http://35.154.16.105:8080/signup/checkMobile',{
method:'post',
headers:{'Content-Type':'application/json'},
body: JSON.stringify({
mobile:this.state.mobile
})
})
.then(response => response.json())
.then(data =>{
if(data.statusCode === '2000'){
localStorage.setItem('mobile',this.state.mobile);
// this.props.loadNewUser(this.state.mobile);
this.props.onRouteChange('otp','nonav');
}
})
// this.props.onRouteChange('otp','nonav');
}
【问题讨论】:
标签: reactjs cookies jwt bearer-token