繁体   English   中英

Redux异步操作不起作用

[英]Redux async action not working

我的应用程式中有这个异步动作,无法正常运作。 我认为错误是在mapDispatchToProps

这是mapDispatchToProps

 const mapDispatchToProps = (dispatch) => { return { fetchUserList: () => { console.log('---In fetchUserList---'); dispatch({ type: FETCH_USER_LIST, payload: new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); console.log('xhr: ', xhr); xhr.open('GET', 'http://localhost:5000/data/fetch/users'); xhr.onload = () => { console.log(' --- in onload function ---'); console.log(xhr.responseText); resolve(JSON.parse(xhr.responseText)); } xhr.onerror = () => { console.log(' --- in onerror function ---'); reject(xhr.statusText); } xhr.send(); }) }); } 

我已经在几个步骤中记录了fetchUserList ,这些步骤确实显示在日志中,但是该方法都无法到达xhr.onloadxhr.onerror因为我没有从那里获取任何日志,是否正确设置了它?

这是我在其中使用的组件:

 class Profile extends Component { constructor(props) { super(props); } componentDidMount() { this.props.fetchUserList(); } } 

如上所述,您的操作应该是纯Java脚本对象,如果您希望

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM