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 });

    }

}

上一篇:redux-thunk使用教程


下一篇:python3.5学习之路_day1_login