在写前端代码的时候会经常用到this.setState()方法进行变量的赋值操做,最近遇到一个比较头痛的问题,在不同的位置使用this.setState()的时候,有时候出现function not define的问题,会出现问题的代码如下:
.then(function (response) {
console.log(" response response ",response);
const {List} = this.state;
})
提示this.setState() undefined 的方法
经过查找资料后发现,是版本的问题,并不是this.setState()本身的问题,而是方法自身定义的问题,经过修改后的代码如下:
.then((response) => {
console.log(" response response ",response);
const {List} = this.state;
})