代码
数据可以打印,但是放到setState里面就报错了,请教各位是哪里的问题。非常感谢!
报错Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined
littlehaker
#4
this 的问题,几个办法:
fetch(url).then((response) => { this.setState(...) })
fetch(url).then(function(response) { this.setState(...) }.bind(this))
var self = this;
fetch(url).then(function(response) { self.setState(...) })