我是fetch的初学者,试图从JSON服务器获取一些数据到我的react native应用程序,但是它总是给我同样的错误...“网络请求失败” 我尝试使用Ip代替“ http://192.168.x.x:3000”之类的localhost,但没有任何变化,我的博览会是192.168.x.x:19000。我忘了做什么?以及为什么总是会发生此错误?
export const fetchDishes = () => (dispatch) => {
dispatch(dishesLoading());
return fetch("http://192.168.1.5:3000/dishes")
.then(
(response) => {
if (response.ok) {
return response;
} else {
var error = new Error(
"Error " + response.status + ": " + response.statusText
);
error.respone = response;
throw error;
}
},
(error) => {
var errmss = new Error(error.message);
throw errmss;
}
)
.then((respone) => respone.json())
.then((dishes) => dispatch(addDishes(dishes)))
.catch((error) => dispatch(dishesFailed(error.message)));
};