【发布时间】:2017-12-22 23:54:40
【问题描述】:
这是我当前工作的登录页面。一切正常
import React, { Component } from 'react';
import {AlertIOS , StyleSheet , View , Text} from 'react-native';
import Button from 'react-native-button';
import {Actions } from 'react-native-router-flux';
class Login extends Component {
render() {
return (
<View>
<Text>Hello world this is login page</Text>
<Button onPress={Actions.login2}>Click </Button>
</View>
);
}
}
export default Login;
但是,我想先调用函数来检查用户名和密码。如果正确,我想进入下一个屏幕。我怎样才能做到这一点。就像下面的这段代码。我真正的问题是我无法弄清楚在渲染方法之外调用Actions.ROUTE_NAME 方法。
//This is not working
import React, { Component } from 'react';
import {AlertIOS , StyleSheet , View , Text} from 'react-native';
import Button from 'react-native-button';
import {Actions } from 'react-native-router-flux';
class Login extends Component {
controlMethod(){
if(true){Actions.login2}
}
render() {
return (
<View>
<Text>Hello world this is login page</Text>
<Button onPress={this.controlMethod}>Click </Button>
</View>
);
}
}
export default Login;
【问题讨论】:
-
这可能会回答你的问题:stackoverflow.com/questions/37346979/…
标签: reactjs react-native react-native-router-flux