未捕获的错误:操作必须是普通对象。使用自定义中间件进行异步操作。

时间:2017-07-01 14:25:44

标签: reactjs redux redux-thunk

我正在构建一个Mern项目,只要我测试POST(将电影添加到购物车),我就会收到此错误,不知道它来自此错误的位置,尝试了一切。

这是我的 Client.js

"use strict"


import React from 'react';
import {render} from 'react-dom' ;
import {Provider} from 'react-redux';
import {Router,Route,IndexRoute, browserHistory} from 'react-router';


import {applyMiddleware, createStore,compose} from 'redux';

import thunk from 'redux-thunk'
import { createLogger } from "redux-logger";


import reducers from './reducers/index';

import {addToCart} from './actions/cartActions';

const middleware =applyMiddleware(thunk, createLogger());
const store = createStore(reducers, middleware);

我在 moviesActions.js

上的功能
import axios from 'axios';
export function postMovies(movie){
    return function (dispatch){
        axios.post("/movies",movie)
            .then(function(response){
                dispatch({type:"POST_MOVIE", payload:response.data})
            })
            .catch(function(err){
                dipsatch({type:"POST_MOVIE_REJECTED", payload:"there was an error while posting a new movie"})
            })

    }
}

0 个答案:

没有答案