Axios将get函数一分为二

时间:2018-12-06 18:25:45

标签: ecmascript-6 redux promise axios es6-promise

我在使用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);
        });
    };
}

它是减少反应器动作的一部分。我想念什么?

0 个答案:

没有答案