我试图做的是保存电子邮件和密码的值。但是,每次我运行此项目时,都会遇到此错误。我收到错误READABLENATIVEMAP TO STRING
。错误的详细信息位于下面的屏幕快照链接中。
import React, { Component } from 'react';
import { View, Text, TouchableOpacity, TextInput, StyleSheet, Button, Alert } from 'react-native';
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
loggedIn: true,
isLoading: true,
email: " ",
password: " ",
}
}
submitForm = () => {
if (this.state.email == "" || this.state.password == "") {
Alert.alert("PLEASE FILL EMAIL AND PASSWORD")
if (this.state.email != "" || this.state.password != "") {
this.loginData();
}
}
}
loginData() {
return fetch('http://192.168.1.150:8080/crm/api/api.php', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
}),
})
.then((response) => response.json())
.then((responseJson) => {
// return responseJson.data;
if (responseJson === 'Data Matched') {
// this.props.navigation.navigate('Second', { Email: UserEmail });
this.props.onHomeviewPress(this.state.data);
}
else {
Alert.alert(responseJson);
}
})
.catch((error) => {
console.error(error);
});
}
// 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}
textContentType="emailAddress"
underlineColorAndroid="transparent"
placeholder="Email"
placeholderTextColor="blue"
textAlign="center"
onChangeText={(email) => this.setState({ email })}
autoCapitalize="none"
/>
<TextInput style={styles.input}
textContentType="password"
underlineColorAndroid="transparent"
placeholder="Password"
placeholderTextColor="blue"
textAlign="center"
onChangeText={(password) => this.setState({ password })}
autoCapitalize="none"
/>
<Button
onPress={this.loginData.bind(this)} title="Login"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
paddingTop: 23,
marginTop: 150,
},
input: {
margin: 15,
height: 40,
borderColor: 'blue',
borderBottomWidth: 1,
borderRadius: 5,
},
});
请检查屏幕截图和我的代码以检测错误并帮助我解决此问题。 预先感谢!