antd disaptch问题

在hanle方法里,我写了2个dispatch方法访问后台,第一个获取的信息作为第二个的请求参数,现在的问题是获取不到最新的role值

hanle() {
    const { dispatch } = this.props
    dispatch({
        type: 'user/fetch',
    });
    const { user:{ role } } = this.props
    dispatch({
        type: 'user/check',
        payload: { role }
    });
}

我怎么获取最新的role值

阅读 1.5k
1 个回答
new Promise(resolve =>{
    dispatch({
        type: 'user/fetch',
        payload: {resolve}  //第一个请求成功 resolve(res)
    }).then(res=>{
        const { user:{ role } } = res;
        dispatch({
            type: 'user/check',
            payload: { role }
        })
    })
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题