redux-thunk
安装
yarn add redux-thunk
配置
// store/index.jsimport { createStore, applyMiddleware, compose } from 'redux'import reducer from './reducer' // 管理员import thunk from 'redux-thunk'const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}): composeconst enhancer = composeEnhancer(applyMiddleware(thunk)) // 增强函数,链式调用。为了兼容 devtoolconst store = createStore(reducer,// window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() // redux// applyMiddleware(thunk) // thunkenhancer)export default store
方法二:
https://www.npmjs.com/package/redux-devtools-extension
import { createStore, applyMiddleware } from 'redux'import thunk from 'redux-thunk'import { composeWithDevTools } from 'redux-devtools-extension'import reducers from './reducers'const store = createStore(reducers, composeWithDevTools(applyMiddleware(thunk)))export default store
