我在使用axios链接诺言时遇到问题:
export const get5DayForecast = () => {
return axios.get('http://localhost:4000/api/weatherForecast').then(res => {
return res;
}).catch(err => {
return err;
});
};
export const load5dayForecast = () => {
return (dispatch) => {
return get5DayForecast.then(res => {
dispatch(load5dayForecastSuccess(res.data));
}).catch(err => {
throw (err);
});
};
另一方面,这种方法可行:
export const load5dayForecast = () => {
return (dispatch) => {
return axios.get('http://localhost:4000/api/weatherForecast').then(res => {
dispatch(load5dayForecastSuccess(res.data));
}).catch(err => {
throw (err);
});
};
}
它是减少反应器动作的一部分。我想念什么?