我是新来的反应者,我正在尝试使用Urban Dictionary API制作Web应用程序字典。问题是当我输出响应参数时,它会显示值,但是当我将状态设置为“定义”时,出现错误,提示Uncaught TypeError: Cannot read property 'setState' of undefined
unirest
.get("https://mashape-community-urban-dictionary.p.rapidapi.com/define")
.query({ term: "explore" })
.headers({
"x-rapidapi-host": "mashape-community-urban-dictionary.p.rapidapi.com",
"x-rapidapi-key": "9196cfb95cmsh64bb4272c1f6e0bp1aa2bejsnb01c091dff35",
useQueryString: true,
})
.end(function (res) {
// displaying
console.log(res.body);
//cannot read | Undefined
this.setState({
define: res.body,
});
});