Node.js undefined不是对象(正在计算';this.login().bind';)

Node.js undefined不是对象(正在计算';this.login().bind';),node.js,express,react-native,Node.js,Express,React Native,因此,我使用React Native创建一个登录表单,并尝试调用一个名为login的方法,该方法将使用我们收到的数据登录用户。当我尝试运行登录页面(使用onPress)时,我得到的只是这个“未定义”错误。这就是错误: undefined不是对象(正在计算'this.login().bind') 我在有问题的代码行添加了一条注释 谢谢 代码: import React,{Component}来自'React'; 从“react native”导入{TextInput、样式表、文本、视图、状态栏、T

因此,我使用React Native创建一个登录表单,并尝试调用一个名为login的方法,该方法将使用我们收到的数据登录用户。当我尝试运行登录页面(使用onPress)时,我得到的只是这个“未定义”错误。这就是错误:

undefined不是对象(正在计算'this.login().bind')

我在有问题的代码行添加了一条注释

谢谢

代码:

import React,{Component}来自'React';
从“react native”导入{TextInput、样式表、文本、视图、状态栏、TouchableOpacity};
从“反应导航”导入{createStackNavigator};
从“../Components/Form”导入表单;
从“../Components/Logo”导入徽标;
从“../Pages/signUp”导入注册;
从“axios”导入axios
导出默认类登录名。组件{
建造师(道具){
超级(道具)
此.state={
用户:未定义,
密码:未定义,
记录:未定义
}
}
render(){
const{navigation}=this.props;
返回(
this.password.focus()}
onChangeText={(text)=>{this.setState({user:text}}}
/>
{this.setState({password:text}}}
ref={(输入)=>this.password=input}
/>  
/*这里有代码错误*/
{this.props.type}登录
)      
}
登录(){
this.setState({logged:false})
axios.get()https://autofeeder.herokuapp.com/',{
参数:{
用户名:this.state.user,
密码:this.state.password
}
})。然后((数据)=>{
this.setState({logged:true})
}).catch((错误)=>{
警报(错误)
})
}
}
const styles=StyleSheet.create({
容器:{
背景颜色:“#00838f”,
弹性:1,
对齐项目:'中心',
辩护内容:“中心”
},
注册按钮:{
颜色:“#ffffff”,
尺寸:16,
重量:'500',
宽度:70
},
signupTextCont:{
背景颜色:“#00838f”,
flexGrow:4,
对齐项目:'中心',
辩护内容:'flex-end',
Margin:16,
},
输入框:{
宽度:300,
背景颜色:“#00838f”,
边界半径:25,
水平方向:16,
尺寸:16,
颜色:“#ffffff”,
玛吉:10,
填充垂直:13
},
按钮:{
宽度:300,
背景颜色:“#1c313a”,
边界半径:25,
玛吉:10,
填充垂直:13
},
按钮文字:{
尺寸:16,
重量:'500',
颜色:“#ffffff”,
textAlign:“中心”
}
});
/*
const styles=StyleSheet.create({
容器:{
背景颜色:“#00838f”,
flexGrow:1,
辩护内容:'中心',
对齐项目:“中心”
},
输入框:{
宽度:300,
背景颜色:'rgba(255255,0.2)',
边界半径:25,
水平方向:16,
尺寸:16,
颜色:“#ffffff”,
玛吉:10,
填充垂直:13
},
按钮:{
宽度:300,
背景颜色:“#1c313a”,
边界半径:25,
玛吉:10,
填充垂直:13
},
按钮文字:{
尺寸:16,
重量:'500',
颜色:“#ffffff”,
textAlign:“中心”
}
}); */
const LoginStack=createStackNavigator({
主页:登录,
注册:注册
})

您已经在
()

上调用了该函数。您可以使用以下语法:

login = () => {
    this.setState({logged:false})
    axios.get('https://autofeeder.herokuapp.com/',{
          params: {
            username: this.state.user,
            password: this.state.password
        }
    }).then((data)=>{
      this.setState({logged:true})
    }).catch((error) =>{
      alert(error)
    })
}
电话:

onPress={this.login()}

绑定应该类似于:

onPress = {this.login.bind(this)}
有关react绑定模式的更多信息,请查看:

onPress={this.login()}
onPress = {this.login.bind(this)}