React native “;如何修复&x2018;手压器’;react native”;中出现错误;
下面是我的登录类代码:React native “;如何修复&x2018;手压器’;react native”;中出现错误;,react-native,React Native,下面是我的登录类代码: export default class Login extends Component { constructor(props) { super(props); this.state = { loggedIn: true, } handlePress = () => { this.props.onHomeviewPress(this.state.data); } } render() {
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
loggedIn: true,
}
handlePress = () => {
this.props.onHomeviewPress(this.state.data);
}
}
render() {
return (
<View style={styles.container}>
<Text style={{ color: "blue", fontSize: 28, marginLeft: 10 }}> Login</Text>
<TextInput style={styles.input}
underlineColorAndroid="transparent"
placeholder="Email"
placeholderTextColor="blue"
autoCapitalize="none"
/>
<TextInput style={styles.input}
underlineColorAndroid="transparent"
placeholder="Password"
placeholderTextColor="blue"
autoCapitalize="none"
/>
<Button
onPress={() => this.handlePress.bind(this)}
title="Login"
/>
</View>
);
}
}
导出默认类登录扩展组件{
建造师(道具){
超级(道具);
此.state={
洛格丁:没错,
}
手按=()=>{
this.props.onHomeviewPress(this.state.data);
}
}
render(){
返回(
登录
这个.把手按.绑(这个)}
title=“登录”
/>
);
}
}
手柄压力功能有问题,不工作,出现错误
undefined不是对象(“this2.handlepress.bind”)
请帮我解决这个问题。提前感谢您的
handlePress
函数已在构造函数中定义
把它移到外面,它就会工作
此外,您不需要绑定函数。只要
onPress={this.handlePress}
就可以了。谢谢Jaon!这很有效