export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: ''};
}
async loginAjax() {
try {
let response = await fetch('http://panel.erzap.com/web_services/login_json/new.json', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
erzap: {
username: this.state.username,
password: this.state.password,
}
})
});
let responseJson = await response.json();
Alert.alert(responseJson.notice);
} catch(error) {
Alert.alert(error);
console.error(error);
}
}
答案 0 :(得分:0)
<TouchableHighlight onPress={() => this.loginAjax()}>
<Text style={styles.btn}>Login</Text>
</TouchableHighlight>
用代码替换这部分代码。这对我有用......
答案 1 :(得分:0)
我编辑了我的代码,现在它完美无缺。
<TouchableHighlight onPress={this.loginAjax.bind(this)}>
<Text style={styles.btn}>Login</Text>
</TouchableHighlight>