react 用fetch 登录,成功后怎么跳转组件
1.登录成功后,后台返回的数据到fetch的data里,然后怎么用路由跳转到其他组件呢
2.如果不用路由,可以用window.location.href来跳转到组件吗
handleSubmit = (e) => {
e.preventDefault();
// let history = this.context.router.history;
this.props.form.validateFields((err, values) => {
if (!err) {
fetch('/api/login',{
method:'POST',
headers: {
'Accept': 'application/json',
'Content-Type':'application/json;charset=UTF-8'
},
body:JSON.stringify({'email':values.email,'password':values.password}),
}).then(function (res) {
return res.json();
}).then(function(data){
console.log(data)
// window.location.href='/usercenter';
}
).catch(function (err) {
console.log(err);
})
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不使用路由,你可以把要跳转的组件引入进来,然后把当前的组件替换掉
fetch成功之后那数据放到state里面,然后在render下面if判断一下根据数据来显示不同的组件