【发布时间】:2016-04-18 12:23:02
【问题描述】:
我正在尝试从使用fetch 函数收到的promise 更新状态。
componentDidMount(){
fetch(url).then((responseText) => {
var response = responseText.json();
response.then(function(response){
this.setState(response);
});
});
}
我收到setState 不是函数的错误
然后,我尝试通过bind(this) 传递this 值,如下所示。
componentDidMount(){
fetch(url).then((responseText) => {
var response = responseText.json();
response.then(function(response){
this.setState(response);
});
}).bind(this);
}
它现在也不起作用。又是同样的错误。
【问题讨论】:
标签: javascript reactjs