【发布时间】:2020-07-27 03:15:36
【问题描述】:
我是 react native 的新手,我尝试将登录类中的数据传递给 auth 函数,但它不起作用。
这是我的身份验证功能
function auth(username, password) {
fetch('http://192.168.178.26:8000/auth/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password })
})
.then(res => res.json())
.then(res => {
saveToken(res.token);
console.log(res.token);
props.navigation.navigate('Home');
})
.catch(error => console.log(error));
构造函数
constructor() {
super()
this.state = {
isReady: false,
username: '',
password: '',
}
this.auth = auth(this.state.username, this.state.password)
...more code
render() {
const {password} = this.state.password;
const {username} = this.state.username;
我的文本输入和登录按钮
<TextInput
placeholder='Email'
...
value={username}/>
<TextInput placeholder='Password'
...
value={password}/>
<TapGestureHandler>
<Animated.View style={style.button} >
<Text style={{ ... onPress={this.auth}>Anmelden</Text>
我已经为此工作了好几天,并在谷歌上搜索了几个小时,但我找不到解决方案。你能帮帮我吗?
最好的问候。
【问题讨论】:
标签: javascript ios react-native parameter-passing constants