WebStorm 警告: Promise returned from xxx is ignored 解决办法

妖狐艹你老母 2023-01-06 01:11 175阅读 0赞

WebStorm 提示内容:

Promise returned from xxx is ignored less… (Ctrl+F1)
This inspection reports function calls that return a Promise that is not later used. These are usually unintended and indicate an error.

这是因为调用的函数加了async, 而 async 声明的函数返回的是一个promise.

在调用这个函数前加一个await声明就可以了, 同时await的这个方法段也要添加async声明才能生效.

  1. async componentDidMount() {
  2. await Common.checkSth();
  3. }

发表评论

表情:
评论列表 (有 0 条评论,175人围观)

还没有评论,来说两句吧...

相关阅读