在继续之前检查 .then() 中的获取请求是否成功
Check for success on get request in .then() before proceeding
在 React 中使用 superagent
,我有一个函数可以将代码发送到 rest api 服务。如果成功,它会发回一个简单的 {"success": true}
。在使用 .then(this.props.setStep(ACCEPTANCE))
将状态设置为另一个视图之前检查成功调用的最佳方法是什么
acceptPromo (e) {
e.preventDefault()
const { offerId } = this.state
superagent
.post('/api/user/offers')
.send({offerId})
.then(this.props.setStep(ACCEPTANCE))
}
我不确定你到底在问什么,但很简单,如果应该就够了
acceptPromo (e) {
e.preventDefault()
const { offerId } = this.state
superagent
.post('/api/user/offers')
.send({offerId})
.then(data => {
if (data.success) {
this.props.setStep(ACCEPTANCE)
}
})
}
在 React 中使用 superagent
,我有一个函数可以将代码发送到 rest api 服务。如果成功,它会发回一个简单的 {"success": true}
。在使用 .then(this.props.setStep(ACCEPTANCE))
acceptPromo (e) {
e.preventDefault()
const { offerId } = this.state
superagent
.post('/api/user/offers')
.send({offerId})
.then(this.props.setStep(ACCEPTANCE))
}
我不确定你到底在问什么,但很简单,如果应该就够了
acceptPromo (e) {
e.preventDefault()
const { offerId } = this.state
superagent
.post('/api/user/offers')
.send({offerId})
.then(data => {
if (data.success) {
this.props.setStep(ACCEPTANCE)
}
})
}