您当前的位置: 首页 >  ar

ITKEY_

暂无认证

  • 0浏览

    0关注

    732博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

RN踩坑‘await‘ expressions are only allowed within async functions and at the top levels of modules.

ITKEY_ 发布时间:2021-05-25 15:11:32 ,浏览量:0

以前很少在循环中执行ajax,今天突然遇到个场景用到。习惯使用map来遍历了,结果在map中遍历无法使用await方法。一时有点懵!!!后来发现普通的for循环中可以遍历。虽然不清楚为什么,但是问题总算是解决了。

错误信息 'await' expressions are only allowed within async functions and at the top levels of modules. 错误代码
this.state.citys.map((item)=>{
      await this.loadWetherInfo(item.location);
 });
正确写法

直接使用for循环遍历就可以了。

const {citys} = this.state;
for (let i = 0; i             
关注
打赏
1665243900
查看更多评论
0.0487s