试图通过有效载荷获取数据但有效载荷不是响应而是请求

时间:2018-02-05 10:44:24

标签: reactjs react-redux axios reducers

我有一个看起来像这样的动作:

import axios from 'axios';

export const GET_LOCATIONS = 'GET_LOCATIONS';

export function fetchLocals() {

    const request = axios.get('http://localhost:3001/api')
    .then(function(response) {
        console.log(response.data)
    })
    .catch(function (error) {
        console.log(error);
    });

    return {
        type: GET_LOCATIONS, 
        payload: request
    };
}

这是我的减速器:

import { GET_LOCATIONS } from '../actions/skyscannerActions.js';

export default function(state=[], action){
    switch (action.type) {
        case GET_LOCATIONS: 
            return [action.payload.data]; 
    }
    return state;
}

由于我的有效负载不是响应而是请求,我无法获取数据,如何从reducer获取response.data?

可能吗?

0 个答案:

没有答案