我正在尝试添加微调器,但是执行程序时出现问题
import React,{Component} from 'react';
import axios from 'axios';
import LoginFailModal from './LoginFailModal';
class Login extends Component
{
constructor(props)
{
super(props);
this.state = {
username : "",
password : "",
error:false,
loading:false
}
}
inputSet =(e)=> {
//console.log(e.target.name);
this.setState({[e.target.name]:e.target.value})
}
loginCheck =(e)=>{
this.setState({['error']:false});
this.setState({['loading']:true});
e.preventDefault();
var data = {
emph : this.state.username,
password : this.state.password
};
axios.post("url",data).then(response=>{
if(response.data.status=='200')
{
var response_data = response.data.data;
var user_data = {'token':response_data.token,
'user_type':'staf'}
localStorage.setItem('user_data', user_data);
this.setState({['error']:true,['loading']:false});
}
else
{
this.setState({['error']:true,['loading']:false});
}
})
}
render()
{
let {loading} = this.state;
return(
<>
{this.state.error ? (<LoginFailModal/>):""}
<div class="row">
<div className="col-xl-7 col-lg-4 col-md-2">
<img className="bg_img" src="assets/images/bg.jpg" alt=""/>
</div>
<div className="col-xl-5 col-lg-4 col-md-2">
<div className="login">
<img className="login-logo" src="assets/images/login-logo.png" alt=""/>
<form className="input">
<input className="text-field" type="text" name="username" onChange={this.inputSet} placeholder="Username" id=""/>
<input className="text-field" type="password" name="password" onChange={this.inputSet} placeholder="Password" id=""/>
<p className="fp">Forgot Password?</p>
<div className="cal">
<div className="row">
<div col-xl-4 col-lg-2 col-md-2>
<p className="sum">40+40</p>
</div>
<div col-xl-5 col-lg-2 col-md-2>
<input className="get" type="text" name="" placeholder="" id=""/>
</div>
</div>
</div>
<div className="row">
<p className="pl-5 remember"><input type="checkbox" name="remember me" id=""/>
Remember me</p>
</div>
<div className="login_button">
<p style={{color: "red"}}>{this.state.error}</p>
<button className="button" onClick={this.loginCheck}>Login
{loading && <i className="fa fa-refresh fa-spin" style={{color:'white'}}></i>}</button>
</div>
</form>
</div>
</div>
</div>
</>
)
}
}
export default Login;