【发布时间】:2018-04-10 17:13:47
【问题描述】:
我有一个返回承诺的静态方法:
static getInfo(ID)
{ return new Promise((resolve, reject) => {
api.getList(ID)
.then((List) => {
resolve(Info);
})
.catch((error) => {
// here I need to access this.props which is undefined
console.log(this.props);
});
.catch(reject);
});
}
this.props 是承诺中的undefined。我怎样才能访问它?
【问题讨论】:
-
您正在尝试以静态方法访问
this。 -
this 的作用域是 promise 而不是 this.props try var self = this 在调用方法之前
-
@FadiAboMsalam:不,上面的函数是箭头函数。 (和
this!= "scope")
标签: javascript reactjs promise