原始的store/index.js文件

    1. import { createStore, applyMiddleware } from 'redux'
    2. // 引入thunk
    3. import thunkMiddleware from 'redux-thunk'
    4. import reducer from './reducer'
    5. const StoreThunk = applyMiddleware(thunkMiddleware)
    6. const store = createStore(reducer, StoreThunk)
    7. // 将reducer导出
    8. export default store

    修改后的文件

    1. import { createStore, applyMiddleware, compose } from 'redux'
    2. // 引入thunk
    3. import thunkMiddleware from 'redux-thunk'
    4. import reducer from './reducer'
    5. const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
    6. // 在applyMiddleware中可以传入多个中间件,也就是说运用多个中间件。
    7. const enhance = composeEnhancers(applyMiddleware(thunkMiddleware))
    8. const store = createStore(reducer, enhance)
    9. // 将reducer导出
    10. export default store