【发布时间】:2018-09-26 22:21:35
【问题描述】:
我在服务器上使用过:
import axios from 'axios';
const Server = axios.create({
baseURL: 'http://localhost:3000/office',
timeout: 5000,
headers: {'accept': 'application/json'}
});
export default Server;
但我无法获取它,我需要帮助从本地 json 服务器获取它。
export function fetchJobs(props) {
return function(dispatch){
dispatch({type: JobsTypes.FETCH_OFFICE});
Server
.get('/office')
.then((response) => {
dispatch({type: JobsTypes.FETCH_OFFICE_SUCCESSFUL,payload:response.data });
})
.catch((err) => {
dispatch({type:JobsTypes.FETCH_OFFICE_FAILED,payload:err});
});
}
}
【问题讨论】:
-
我觉得你需要改一下
baseURL: 'http://localhost:3000' -
@PritishVaidya 试过了,还是一样。谢谢。
-
你得到什么错误?同时尝试记录错误和响应。
-
没有错误,页面只是空白,在网络响应中没有localhost 3000
-
您正在尝试使用调试模式对吗?
标签: reactjs react-native fetch json-server