【发布时间】:2017-07-24 14:12:26
【问题描述】:
在下面的代码中,如果第一次调用失败并且第二次调用返回响应,则在 catch 块中更新的 cp 值不能作为 props 使用。 cp 有错误,这是第一次调用的响应。我需要在我的组件中提供第二次调用的响应
cp = getcp() // getcp returns promises
cp.catch(ex => {
if (ex) {
cp = getcp()
cp.catch(ex => {
cp = {}
})
} else {
cp = {}
}
})
我将路由中的 cp 值作为<Route path={ PAGE } component={ component } onEnter={ refresh } cp={ cp }/> 发送,并且在组件中我正在使用 this.props.route.cp
如果第一次调用成功,则正确传递 cp。 chid 组件中的 this.props.route.cp 返回 cp 值。这实际上只在第二次调用时失败
【问题讨论】:
标签: javascript reactjs promise react-router react-redux