Skip to content

Instantly share code, notes, and snippets.

@mayneyao
Last active November 1, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayneyao/7d8185b855f7a61618379f22958d28be to your computer and use it in GitHub Desktop.
Save mayneyao/7d8185b855f7a61618379f22958d28be to your computer and use it in GitHub Desktop.
react中使用js防抖校验邮箱
onEmailChange = (e) => {
e.persist();
this.setState({
email: e.target.value
}, () => {
this.checkEmail(e.target.value)
})
};
checkEmail = (email) => {
axios.post('/account/check_register_email', {
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