React native React Native、Expo、Axios的计算机权限问题
在React Native with Axios中,我正在使用Axios向远程url发出请求。如果我试图提出请求,就会不断出现此错误React native React Native、Expo、Axios的计算机权限问题,react-native,axios,expo,React Native,Axios,Expo,在React Native with Axios中,我正在使用Axios向远程url发出请求。如果我试图提出请求,就会不断出现此错误 The file “Macintosh HD” couldn’t be opened because you don’t have permission to view it. 以下是我的一些代码: // inside componentDidLoad() ExampleService.index().then(response => { conso
The file “Macintosh HD” couldn’t be opened because you don’t have permission to view it.
以下是我的一些代码:
// inside componentDidLoad()
ExampleService.index().then(response => {
console.log('service response: ',response);
})
我通过在组件中直接使用fetch解决了这个问题,但是我想使用更抽象的“服务”模式。我通过在组件中直接使用fetch解决了这个问题,但是我想使用更抽象的“服务”模式。
// in side ExampleService.js
function index() {
return client({
url: `/`,
method: 'GET'
});
}
// inside client
const client = axios.create({
baseUrl: 'http://192.168.42.64:3000',
headers: {
// 'Authorization': authHeader,
'Content-Type': 'application/json'
}
});