Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t将数据从动作传递到减速器_Javascript_Reactjs_Redux - Fatal编程技术网

Javascript Can';t将数据从动作传递到减速器

Javascript Can';t将数据从动作传递到减速器,javascript,reactjs,redux,Javascript,Reactjs,Redux,从服务器获取响应并尝试分派 我的行动: import axios from 'axios' import { INCOME_LIST } from '../actionTypes' function receiveData(json) { return{ type: INCOME_LIST, data: json } }; export function IncomeList () {

从服务器获取响应并尝试分派

我的行动:

import axios from 'axios'
import { INCOME_LIST } from '../actionTypes'

    function receiveData(json) {
        return{

            type: INCOME_LIST,
            data: json
        }
    };


    export function IncomeList () {

        return dispatch => {

            return (
                console.log(response.data);
                axios.post('http://api.hylaa.net:8084/course/income/outline',{}, {
          headers: { 'X-Authenticated-Userid': '15000500000@1' }
         }).then(function (response) {

                    dispatch(receiveData(response.data.body));

                })

                )
        }
    }
我的减速机:

import { INCOME_LIST } from '../actionTypes'

import Immutable from 'immutable'

const initialUserState = {
  list: [
            {
                "last_month": 501,
                "current_month": 1021,
                "total": 1521
             }

         ]
}

    const listReducer = function(state = initialUserState, action) {
       console.log('actiondata in reducer:' + action.data);

      switch(action.type) {

      case 'INCOME_LIST': 
             return Object.assign({}, state, { list: action.data });

      default: 

      return state;
      }


}

export default listReducer
console.log('reducer中的actiondata:'+action.data)-这是什么时候没有定义的

尝试console.log操作,console.log不工作。如何将数据从Action传递到reducer?是否认为我需要在组件中初始化操作

尝试在组件中执行此操作

import { IncomeList } from '../../actions/income'
    componentDidMount() {

      this.props.IncomeList()

        } - says ImcomeList is not a func

您需要从组件调用
操作。为此,您需要先将其绑定到道具。为此,请使用
MapDispathToprops
组件

import {IncomeList} form './path/to/MyAction';
import { bindActionCreators } from 'redux';

class App extends React.Component {
    constructor(props) {
       super(props);
    }
    componentDidMount() {
      this.props.IncomeList
    }
    render() {
         ......
    }
}

function mapDispatchToProps(dispatch) {
    return {
       IncomeList: bindActionCreators({IncomeList}, dispatch);
    }
}

您是否检查了
receiveData(json)
中的
json
是否已定义?是的,我在我的组件中进行了检查,请求相同。这是工作,我看不到任何console.log。可能我需要在某个地方连接它?例如,我需要将actionCreator导入我的减速器或组件吗?