-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createAjaxAction 中的dispatch 如何传进去的? #7
Comments
function createThunkMiddleware(extraArgument) {
}; const thunk = createThunkMiddleware(); export default thunk; |
createThunkMiddleware这个方法哪里找到的? |
@youngList 本项目引用的是redux-thunk作为异步action的处理中间件,createThunkMiddleware 可以在以下网站找到 |
@hq229075284 ok,谢谢了 |
export const createAjaxAction = (api, startAction, endAction) => (data, cb, reject) =>
(dispatch) => { //dispatch 怎么传进来的
let respon
startAction && dispatch(startAction())
// eslint-disable-next-line no-param-reassign
// 每个请求带上token
const token = sessionStorage.getItem('token')
if (token) {
if (!data) {
data = {}
}
data.token = token || null
}
data = isArray(data) ? data : [data]
api(...data)
.then(checkStatus) // eslint-disable-line no-use-before-define
.then(response => response.json())
.then((resp) => {
respon = resp
endAction && dispatch(endAction({ req: data, res: resp }))
})
.then(() => {
if (respon.status === 1) {
cb && cb(respon)
} else {
if (respon.errorCode == '101') {
logOut()
} else {
if (typeof (reject) === 'function') {
reject(respon)
} else {
message.error(respon.msg)
}
}
}
})
.catch(catchError) // eslint-disable-line no-use-before-define
}
然后在组件中调用 this.props.dispatch(fetchHouseCheckList({ currentPage: 1 }))
在这里dispatch 不应该是一个action 么?
fetchHouseCheckList({ currentPage: 1 }) 返回的是一个function,
并且 上面中的 参数 dispatch 是如何传进去的呢?
蟹蟹。
The text was updated successfully, but these errors were encountered: