错误信息 react TypeError: Cannot read property 'up' of undefined at
错误信息 react Unhandled Rejection (TypeError): Cannot read property 'setState' of undefined
解决方法
您的ajax请求中的回调函数未绑定。当您将一个函数传递给另一个函数(作为回调)时,“ this”将是对它最终被调用时所处上下文的引用,而不是您编写它时所处的上下文。如果使用箭头功能,它将保留编写时的上下文。 your callback function from the ajax request is not bound. When you pass a function to another function (as a callback), "this" will be a reference to the context it is in when it is finally called, as opposed to what it is when you wrote it. If you use an arrow function, it will keep the context it had when you wrote it.
.then(function(res){
this.setState({intentOptions: res.data});
});
如果将此功能设置为箭头功能,则应解决该问题。 If you make this function an arrow function, the issue should be resolved.
.then((res) => this.setState({intentOptions: res.data}));