javascript - react :Parsing error: await is a reserved word

标签 javascript async-await

./src/App.js

Line 15: Parsing error: await is a reserved word

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();

如何消除这个错误?

最佳答案

由于您是这门语言的新手,我建议您不要使用这种方式。这就是所谓的箭头函数

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=()=> { /*...*/ }

希望这有帮助!

关于javascript - react :Parsing error: await is a reserved word,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52967965/

相关文章:

javascript - 对于网站 : How do I make an image follow the mouse pointer only in a certain area?

javascript - 更改 'window' 时,存储在 'Window.location.href' 对象上的属性将被删除

c# - 异步 WCF 调用来保存线程?

c# - 为什么我的异步函数在调用 task.run 函数时挂起

wpf - 异步 MVVM 命令

javascript - 使用 :last-child and :first-child with jQuery

javascript - 如何在html中在小屏幕上显示图像和在大屏幕上显示视频

javascript - 异步函数返回一个 promise

node.js - Nodejs、TypeScript、ts-node-dev 和顶级等待

javascript - 使用 es6 迭代多维对象