Last active
November 1, 2018 09:39
-
-
Save mayneyao/7d8185b855f7a61618379f22958d28be to your computer and use it in GitHub Desktop.
react中使用js防抖校验邮箱
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onEmailChange = (e) => { | |
e.persist(); | |
this.setState({ | |
email: e.target.value | |
}, () => { | |
this.checkEmail(e.target.value) | |
}) | |
}; | |
checkEmail = (email) => { | |
axios.post('/account/check_register_email', { | |
}).then(res => { | |
if (res.data.has_email_registered) { | |
this.setState({ | |
emailRegistered: true, | |
msgOpen: true, | |
msg: '此邮箱已注册' | |
}) | |
} else { | |
this.setState({ | |
emailRegistered: false, | |
msgOpen: false, | |
}) | |
} | |
}) | |
}; | |
constructor(props) { | |
super(props); | |
this.state = { | |
msgOpen: false, | |
msg: '', | |
emailRegistered: false | |
}; | |
this.checkEmail = _.debounce(this.checkEmail, 500) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment