1 回答
TA贡献1797条经验 获得超4个赞
我认为最简单的方法是在状态中存储一个布尔值,然后在渲染中创建一个三元组。根据您的需要更改布尔值。
onSubmit = () => {
document.getElementById('error-alert').innerHTML = "";
this.setState({showLoading: true});
<span class="btn btn-light border-1 border-dark mdi mdi-loading mdi-spin mdi-24px"></span>`;
fetch("my server link here", {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
name: this.state.name
})
})
.then(response => response.json())
.then(user => {
if (user.id) { // if the input is correct (response true from the server)
this.props.loadUser(user)
this.props.onRouteChange('home');
} else {
this.setState({showLoading: false});
}
render(){
return(
<div>{show ?
<Loading/>
:
<div
className="btn btn-light border-1 border-dark"
onClick={this.onSubmit}
>Register
</div>
}
)
}
添加回答
举报