javascript - reactjs:解析错误:await是保留字
问题描述
./src/App.js
第 15 行:解析错误:await 是保留字
13 | getWeather = async=()=>{
14 |
15 | const api_call = await fetch('http://api.openweathermap.org/data/2.5/weather?q=Manchester,uk&appid=${API_KEY}');
| ^
16 |
17 | const data = await api_call.json();
我怎样才能摆脱这个错误?
解决方案
由于您是这种语言的新手,我建议您不要使用这种方式。那就是所谓的arrow function
。
async () => { /*...*/ };
// same to
async function () { /*...*/ };
并将其与参数一起使用:
async (param_1, param_2) => { /*...*/ };
// same to
async function (param_1, param_2) { /*...*/ };
在您的情况下,问题可能来自
// remove "=" character after "async" keyword here
async=()=> { /*...*/ }
希望这可以帮助!
推荐阅读
- google-apps-script - 如何在谷歌应用脚本中通过 url 从图像中获取 EXIF?
- java - 忽略整个项目中的所有测试用例
- r - 使用连接中的字符向量通过引用分配多列
- javascript - Javascript如何使用已经提供的时间(以秒为单位)继续计时器
- image - Flutter Image Widget:如何将 Image 小部件转换为 Byte 数组
- c++ - 是否可以在没有头文件的情况下链接 dylib?
- r - 基于多个字符串的部分匹配的 R 数据框中的子集行
- c# - 在 MS 单元测试 (.NET Core) 中设置 System.Diagnostics.Activity.Current
- .net - .NET Core 2.2 Angular6 - 路由模板中的参数不完整
- ajax - AJAX 请求后光标插入符号总是改变