How can I use async/await in a es6 javascript class?

后端 未结 2 1138
抹茶落季
抹茶落季 2021-01-27 02:39

So I\'m trying to make a function of a class I made async, but webpack gives me an error when compiling the class.

My code would be something like this:

         


        
相关标签:
2条回答
  • 2021-01-27 03:03

    Yep, so I didn't realized that I hadn't added to my .babelrc file the stage-0 preset that includes async/await.

    The code works just fine.

    EDIT: As RGraham says, stage-3

    0 讨论(0)
  • 2021-01-27 03:08

    async/await is part of ES7 proposal. SO you need to use babel/traceur to compile your code to ES6/ ES5

    0 讨论(0)
提交回复
热议问题