0

这是我的我尝试过但无法解决这个简单的问题

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);
4

1 回答 1

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+");它对我有用。

于 2017-03-28T07:49:08.187 回答