redux中的异步action

我的action如下

export function PostMoviesIn(url){
    return function(dispatch){
        dispatch(StartRquest(url));
        console.log(1)
        return axios.get('/api'+url).then((res)=>{
            dispatch(EndRequest(url, res['subjects']));
        }
        )
    }
}

export function PostMoviesTop(url){
    return function(dispatch){
        dispatch(StartRquest(url));       
        return axios.get('/api'+url)
              .then((res)=>{
                 dispatch(EndRequest(url, res['subjects']));
        }
        )
    }
}

connect的配置如下

const mapDispatchToProps = (dispatch) => {
    return {
        getIn: () => dispatch(PostMoviesIn('/v2/movie/in_theaters')),
        getTop: () => dispatch(PostMoviesTop('/v2/movie/in_theaters'))
    }
}

通过provider将store传到子组件,我在子组件中调用如下

 getInTh(){
        this.props.getTop()
    }

发现根本执行不到异步action的then中,不会发出请求,请大佬帮忙解决

阅读 1.7k
1 个回答

你可以检查下是不是请求出错了,所有没有走到.then()方法里。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题