【发布时间】:2018-08-25 08:08:24
【问题描述】:
我正在做一个大型项目,但遇到了一些问题。
每次点击登录按钮,都需要一段时间才能建立数据库连接,如果这个按钮是alert,你点击多次,它也会多次显示alert。
这是按钮:
<TouchableOpacity
style={styles.submitButton}
onPress={
() => this.login(this.state.email, this.state.password)
}>
<Text style={styles.submitButtonText}>Login</Text>
</TouchableOpacity>
我想在点击按钮后禁用它,这样警报错误只会出现一次。
这是我要放置禁用按钮的代码的地方:
if (respo == 'Wrong name or password.') {
alert("Wrong Username and Password.");
} else {
if (respo.user.uid > 0) {
if (Object.values(respo.user.roles).indexOf("student user") > -1) {
AsyncStorage.setItem("u_uid", respo.user.uid);
alert("Login Successfull.");
Actions.home();
} else {
alert("Only Student user is allowed to login.");
}
}
}
谢谢!
【问题讨论】:
-
为什么不使用带有
disabled属性的Button组件? -
因为它不会将
styles作为prop,并且color proprenders对于android和ios的不同视图。请检查文档@987654321 @
标签: reactjs button react-native native