【发布时间】:2020-03-06 16:07:35
【问题描述】:
以下代码部分无法编译为什么您无法识别容器类中的运算符 this。
class MyComponent {
public data: Array<Object>;
public someAttribute: string;
async constructor() {
let info = await this.getData('http://localhost:8080/api/users')
let check = function (data) {
this.someAttribute = data.someAttribute
}
check(info)
}
}
【问题讨论】:
-
好吧,我看到您正在尝试访问
this.getData,但我在任何地方都没有看到它的定义... -
你不能有一个异步构造函数。
-
这看起来根本不像 ES6 代码。你在用打字稿吗?
标签: typescript