React - native - fetch不是函数?

时间:2018-03-04 12:54:10

标签: reactjs react-native react-router react-native-android

This is my error code

您好,我在从PHP脚本中获取JSON数据时遇到问题。这一切都工作正常,但当我添加app.js路由条件等等它已停止工作并返回此错误。 (在注册和登录工作之前 - 现在没有人,但我没有编辑任何从PHP获取数据的代码)不知道哪里可能是那个问题?

export default class Login extends Component<> {
constructor(props){
    super(props);
    this.state = {
        userEmail: '',
        userPassword: ''
    }
}
userLogin = () => {
    //  alert('ok');
    const {userEmail} = this.state;
    const {userPassword} = this.state;


    fetch('https://link', {
        method: 'post',
        header: {
            'Accept': 'application/json',
            'Content-type': 'application/json',
        },
        body: JSON.stringify({
            email: userEmail,
            password: userPassword,
        })

    }).then((response) => response.json()).then((responseJson) => {
        alert(responseJson);
    }).catch((error) => {
        console.error(error);
    });
}
signup(){
    Actions.signup();
}
render() {
    return(
        <View style={styles.container}>
            <Logo/>
            <TextInput onChangeText = {userEmail => this.setState({userEmail})} style={styles.inputBox} underlineColorAndroid='rgba(0,0,0,0)' placeholder="Email" placeholderTextColor = "#ffffff"/>
            <TextInput onChangeText = {userPassword => this.setState({userPassword})} style={styles.inputBox} underlineColorAndroid='rgba(0,0,0,0)' placeholder="Heslo" placeholderTextColor = "#ffffff" secureTextEntry={true} />

            <TouchableOpacity style={styles.button} onPress={() => this.userLogin()}>
                <Text style={styles.buttonText}>Login</Text>
            </TouchableOpacity>
            <View style={styles.signupTextCont}>
                <Text style={styles.signupText}>No account</Text>
                <TouchableOpacity onPress={this.signup}><Text style={styles.signupButton}>Register</Text></TouchableOpacity>
            </View>
    </View>
    )
}

这是我的登录代码,当我点击Login时会发生此错误。

0 个答案:

没有答案