所以我試圖做一個類我做異步的功能,但編譯類時,webpack給我一個錯誤。如何在es6 javascript類中使用async/await?
我的代碼將是這樣的:
class MyClass {
constructor(apiService) {
this._apiService = apiService;
}
async updateInformation() {
await this._apiService.updateInformation();
// .. do more stuff I have to do
}
}
的錯誤的WebPack給我的是:
Module build failed: SyntaxError: Unexpected token
(該意外標記點的 'U' 異步後)
什麼是您的捆綁/轉換器設置? babel6,webpack ... –
'async/await'不是ES6的一部分,所以它不會在(僅)支持ES6的環境中運行。您需要先將其轉換爲ES6代碼(例如,使用Babel或再生器)。 –