fou*_*rix 2 javascript promise reactjs redux redux-thunk
我的项目正在使用react,redux和redux-thunk。
我想等待功能结束,然后再启动清除页面的功能。不幸的是,我在.then中访问函数时遇到问题
这是我以前的没有承诺的代码,然后:
this.props.dispatch(ScheduleAction(..))
this.props.deleteTab()
Run Code Online (Sandbox Code Playgroud)
问题是在将信息发送到我的服务器之前有时调用了deleteTab(),所以效果不是很好。
然后我做到了:
Promise.resolve(this.props.dispatch(ScheduleAction(..)))
.then(function(response) {
this.props.deleteTab();
console.log("TabDeleted !!!");
return response
})
Run Code Online (Sandbox Code Playgroud)
现在的问题是我无法访问 this.props.deleteTab();
我有这个错误:
未捕获(承诺)TypeError:无法读取未定义的属性“ props”
如果有人对如何通过.then中的道具进行修复有任何想法,请先谢谢!
小智 8
尝试这个。那时您将无法访问此文件。如果使用以下箭头方法,则应该可以访问它。
Promise.resolve(this.props.dispatch(ScheduleAction(..)))
.then((response)=> {
this.props.deleteTab();
console.log("TabDeleted !!!");
return response
})
Run Code Online (Sandbox Code Playgroud)