redux-thunk记录

1、安装redux-thunk 命令: npm install --save redux thunk
2、在stroe下inde.js中引入 import thunk from 'redux-thunk',配合redux提供的applyMiddleware方法使用。

import {createStore,compose, applyMiddleware} from 'redux'
// 引入thunk
import thunk from 'redux-thunk'
import reducer from './reducer'

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const store = createStore(reducer,composeEnhancers(
  applyMiddleware(thunk)
))

export default store

猜你喜欢

转载自blog.csdn.net/weixin_39786582/article/details/82623821