原始的store/index.js文件
import { createStore, applyMiddleware } from 'redux'
// 引入thunk
import thunkMiddleware from 'redux-thunk'
import reducer from './reducer'
const StoreThunk = applyMiddleware(thunkMiddleware)
const store = createStore(reducer, StoreThunk)
// 将reducer导出
export default store
修改后的文件
import { createStore, applyMiddleware, compose } from 'redux'
// 引入thunk
import thunkMiddleware from 'redux-thunk'
import reducer from './reducer'
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
// 在applyMiddleware中可以传入多个中间件,也就是说运用多个中间件。
const enhance = composeEnhancers(applyMiddleware(thunkMiddleware))
const store = createStore(reducer, enhance)
// 将reducer导出
export default store