【发布时间】:2022-12-14 03:38:14
【问题描述】:
在我的代码中,我使用的是 react-native: 0.66.1 并且我已经安装了 dotenv: ^10.0.0。 .env 文件代码
API_LOGIN=https://example.in/login
应用程序.js 文件
require('dotenv').config();
class UserLogin extends Component{
//some code here
apiCallHere=()=>{
const url=process.env.API_LOGIN;
fetch(url,{
method: 'POST',
body: JSON.stringify({
email: email,
password: password
}),
headers: new Headers({
'Content-Type': 'application/json',
})
}).then(res => res.json())
.catch(error => console.error('Error: ', error))
.then((response) => {
if (response.access_token != undefined) {
this.setState({
accessToken : response.access_token,
});
if(this.state.accessToken != ''){
this.props.navigation.navigate('UserHomePage');
}
}
else{
alert('Unauthorised User');
}
})
}
}
请帮我解决这个问题。我找不到问题所在。我是 React Native 的新手
【问题讨论】:
标签: reactjs react-native