这是我尝试了但无法解决这个简单的问题
export default class LoginScene extends Component {
constructor(props) {
super(props);
this.state = {
userid: '',
password: '',
};
}
componentWillMount() {
// this.fetchData();
}
veryfyLogin() {
fetch(LOGIN_URL)
.then((response) => {
if (response.status === 200) {
var navigator = this.props.navigator;
navigator.push({
id: 'dashboard',
title: 'DashBoardScene',
index: 1
});
}
Alert.alert(response.status);
})
.done();
}
render() {
onButtonPress = () => {
Alert.alert("userid:::"+this.state.userid+"Password:::"+this.state.password);
this.veryfyLogin();
};
return (
<View >
<Text> User Name: </Text>
<TextInput
style={{ height: 40 }}
ref= {(el) => { this.userid = el; }}
placeholder="enter your email address"
onChangeText={(userid) => this.setState({ userid })}
value={this.state.userid}
/>
<Text> Password: </Text>
<TextInput
ref= {(el) => { this.password = el; }}
style={{ height: 40 }} password={true}
placeholder="password"
onChangeText={(password) => this.setState({ password })}
value={this.state.password}
/>
<Button
title="Login"
color="#841584"
onPress={onButtonPress}
accessibilityLabel="Learn more about purple"
/>
</View>
)
}
}
LoginScene.propTypes = {
title: PropTypes.string.isRequired,
// onForward: PropTypes.func.isRequired,
// onBack: PropTypes.func.isRequired,
};
AppRegistry.registerComponent('LoginScene', () => LoginScene);
答案 0 :(得分:0)
代码中存在小错误
veryfyLogin() {
fetch(LOGIN_URL)
.then((response) => {
if (response.status === 200) {
var navigator = this.props.navigator;
navigator.push({
id: 'dashboard',
title: 'DashBoardScene',
index: 1
});
}
Alert.alert(response.status);
})
.done();
}
Alert.alert(response.status);
期待一个字符串,但这里的response.status是添加Alert.alert(response.status+")
后的整数;它对我有用。