背景作用
- redux 中的store 仅支持同步数据流。使用
thunk
等中间件可以帮助在 redux 应用中实现异步性。
redux-thunk使用流程
- 下载 npm install redux-thunk -S
- store中引入redux-thunk中间件
- store中挂载redux-thunk实例
import {createStore,applyMiddleware} from 'redux'
import reducer from './reducer'
// redux-thunk 中间价 是store支持异步派发
import thunk from 'redux-thunk'
const store = createStore(reducer,applyMiddleware(thunk));
export default store
- 组件中的异步派发
this.props.dispatch((next)=>{ // 异步派发函数
axiosList.getData(next) // axios请求
})
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。