|
|
@@ -37,12 +37,12 @@ class LoginInput extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
login = () => {
|
|
|
let _this = this;
|
|
|
+ this._isMounted = true;
|
|
|
// let loginUrl = `http://localhost:8999/login`;
|
|
|
|
|
|
- if (this.state.login_username !== '' && this.state.login_password !== '') {
|
|
|
+ if (this.state.login_username !== '' && this.state.login_password !== '' ) {
|
|
|
axios.post(loginUrl, {
|
|
|
'user-name': this.state.login_username,
|
|
|
password: this.state.login_password
|
|
|
@@ -56,10 +56,12 @@ class LoginInput extends Component {
|
|
|
setCookie("user_id", res.data);
|
|
|
_this.props.getUserId(res.data);
|
|
|
request(graphqlUrl, GET_USER, {id: res.data}).then(data => {
|
|
|
- this.setState({
|
|
|
- avatar: data.user_by_id.avatar,
|
|
|
- nickname: data.user_by_id.nickname
|
|
|
- })
|
|
|
+ if (this._isMounted) {
|
|
|
+ this.setState({
|
|
|
+ avatar: data.user_by_id.avatar,
|
|
|
+ nickname: data.user_by_id.nickname
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
)
|
|
|
})
|
|
|
@@ -181,6 +183,7 @@ class LoginInput extends Component {
|
|
|
|
|
|
componentWillMount() {
|
|
|
let _this = this;
|
|
|
+ this._isMounted = true;
|
|
|
axios.get(getIdUrl)
|
|
|
.then((res) => {
|
|
|
if (res.data !== '') {
|
|
|
@@ -191,15 +194,16 @@ class LoginInput extends Component {
|
|
|
loginOnce: false,
|
|
|
loginStatus: 'logined'
|
|
|
}, () => {
|
|
|
- request(graphqlUrl, GET_USER, {id: res.data}).then(data => {
|
|
|
+ request(graphqlUrl, GET_USER, {id: res.data}).then(data => {
|
|
|
+ if (this._isMounted) {
|
|
|
this.setState({
|
|
|
avatar: data.user_by_id.avatar,
|
|
|
nickname: data.user_by_id.nickname
|
|
|
})
|
|
|
}
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
+ }
|
|
|
+ )
|
|
|
+ });
|
|
|
}
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
@@ -207,6 +211,10 @@ class LoginInput extends Component {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ componentWillUnmount() {
|
|
|
+ this._isMounted = false
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
return (
|
|
|
<div>
|