Skip to content

Commit

Permalink
feat(login): 添加login请求
Browse files Browse the repository at this point in the history
  • Loading branch information
lcx committed Mar 16, 2020
1 parent 45dc2cb commit 63177ab
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/components/login.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import '../css/login.css'
import UserInput from './UserInput'
import axios from 'axios';
import qs from 'qs'

class Login extends React.Component {
constructor(props){
constructor(props) {
super(props);
this.state = {
username: '',
Expand All @@ -14,57 +16,67 @@ class Login extends React.Component {

onInputChange = (e) => {
const flag = e.target.value !== '' ? false : true
if(e.target.placeholder === 'Username') {
this.setState({username: e.target.value, emptyName: flag});
if (e.target.placeholder === 'Username') {
this.setState({ username: e.target.value, emptyName: flag });

}
if(e.target.placeholder === 'Password') {
this.setState({password: e.target.value, emptyPsw: flag});
if (e.target.placeholder === 'Password') {
this.setState({ password: e.target.value, emptyPsw: flag });
}
console.log(flag, this.state);

// if(flag) {
// e.target.parentNode.style['border-color'] = 'rgb(245,34,45)';
// e.target.parentNode.style['box-shadow'] = 'none';
// console.log(e.target.parentNode);

// }
}

login = (e) => {
console.log(this.state);
if(this.state.password === ''){
this.setState({emptyPsw: true});
if (this.state.password === '') {
this.setState({ emptyPsw: true });
}
if(this.state.username === '') {
this.setState({emptyName: true});
if (this.state.username === '') {
this.setState({ emptyName: true });
}

axios.post('http://localhost:3001/login', qs.stringify({
username: this.state.username,
password: this.state.password,
})).then(res => {
console.log(res, 111);

}).catch((error) => {
console.log(error, 222);

});

}

render() {
return <form className="login-box">
<UserInput
placeholder='Username'
iconType='user'
inputType='text'
<UserInput
placeholder='Username'
iconType='user'
inputType='text'
onChange={this.onInputChange}
/>
<UserInput
placeholder='Password'
iconType='lock'
<UserInput
placeholder='Password'
iconType='lock'
inputType='password'
onChange={this.onInputChange}
/>
<div className='item3'>
<p>
<input id="check" className="check" type="checkbox" />
<input id="check" className="check" type="checkbox" />
<label htmlFor="check"></label>
<span>Remember me</span>
<a href='aa'>Forgot password</a>
</p>

<button type='button' onClick={this.login}>Log in</button>
<p>Or <a href='aa'>register now!</a></p>
</div>
Expand Down

0 comments on commit 63177ab

Please sign in to comment.