javascript - 在反应中一个接一个地运行功能
问题描述
之后setState
,我想调用service.logout()
,然后Auth.logout()
函数,
componentWillMount() {
if (!(this.Auth.loggedIn())){
this.props.history.replace('/login');
} else {
this.setState({token : this.Auth.getToken()}).then(service.logout(this.state.token)).then( this.Auth.logout())
// console.log('token',this.state.token)
}
}
但我变得error
这样了,
TypeError: Cannot read property 'then' of undefined
Logout.componentWillMount
src/components/auth/Logout.js:20
17 | if (!(this.Auth.loggedIn())){
18 | this.props.history.replace('/login');
19 | } else {
> 20 | this.setState({token : this.Auth.getToken()}).then(service.logout(this.state.token)).then( this.Auth.logout())
21 | // console.log('token',this.state.token)
22 |
23 | }
解决方案
推荐阅读
- junit - Camel @Produces 单元测试
- json - 将 IPv4 地址的 \n 列表格式化为 json
- javascript - 删除 Webpack 中重复的 Promise polyfill
- microsoft-graph-api - 使用 oauth2 登录 Microsoft 帐户时出现 Safari 错误
- delphi - TFDMemtable FieldDefs 不考虑查找字段?
- python - 如何通过减少循环和调节来优化我的代码
- css - 元素选择器在 Worpress 站点的样式表中不起作用
- vb.net - 如何在visual basic代码中计算平均值?
- react-native - 如何在反应原生的webview中嵌入来自json数据的视频?
- javascript - 为什么这返回未定义而不是值?