redux-ajax
v1.0.5
Published
the ajax middleware for redux
Downloads
8
Readme
redux-ajax
redux-ajax是一款redux中间件,依赖于jquery
redux-ajax demo
- 进入项目文件夹安装npm模块
npm install redux-ajax --save-dev
- store中引入redux-ajax
import { createStore, applyMiddleware } from 'redux'
import ajaxMiddleware from 'redux-ajax'
const createStoreWithMiddleware = applyMiddleware(
ajaxMiddleware
)(createStore)
const store = createStoreWithMiddleware(rootReducer, initialState)
- action中加入相关一部action
export function getRemoteData(url) {
return {
type: GET_REMOTE_DATA,
ajax:true,
ajaxParam:{
url: url,
type: 'get',
dataType: 'json'
},
callBack(v,dispatch){
//此为ajax的回调函数
},
failCallBack(v,dispatch){
//此为ajax的失败回调函数
}
}
}