报错Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined

#1

代码

数据可以打印,但是放到setState里面就报错了,请教各位是哪里的问题。非常感谢!

#2

fetch 后面的then 的function去掉,并且使用箭头函数,这是es6方面的知识

#3

应该说是js基础,this的绑定问题

#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(...) })
#5

感谢,不报错了