redux-thunk形式
作者:互联网
onClick(e) {
e.preventDefault();
const { user, pass } = this.refs;
this.props.dispatch(login(user.value, pass.value));
}
export const login = (user, pass) => async (dispatch)
export const login = (user, pass) => async (dispatch) => {
try {
dispatch({ type: LOGIN_REQUEST });
let { data } = await request.post('/login', { user, pass });
await dispatch(loadUserData(data.uid));
dispatch({ type: LOGIN_SUCCESS, data });
} catch(error) {
dispatch({ type: LOGIN_ERROR, error });
}
}
标签:const,形式,dispatch,thunk,user,pass,login,redux,LOGIN 来源: https://www.cnblogs.com/feng9exe/p/11728045.html