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

    }

}

posted @ 2019-10-23 18:46  zzfx  阅读(133)  评论(0编辑  收藏  举报