【发布时间】:2021-03-14 21:57:38
【问题描述】:
我正在使用:
"react-native": "0.63.3",
"axios": "^0.21.0",
"react": "16.13.1",
这是一个简单的请求,看看发送请求是否成功:
useEffect(() => {
console.log('log here fast');
axios
.get('http://api.github.com/users/hacktivist123/repos')
.then(function (response) {
console.log('axios', response);
})
.catch(function (error) {
console.log('axios error', error);
});
fetch('http://api.github.com/users/hacktivist123/repos')
.then((response) => response.json())
.then((data) => console.log(data));
console.log('log here slow');
}, []);
它甚至没有显示请求是否已发送。我在真实设备上运行了这个项目,它运行良好,我尝试了其他问题中给出的解决方案,但没有一个有效。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.tasks">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="28"
>
即使添加 network_security_config.xml 也没有帮助,也没有让构建项目出现一些错误。
【问题讨论】:
标签: android react-native axios fetch