如何设置反应状态?

时间:2020-06-06 11:25:38

标签: javascript reactjs

我是新来的反应者,我正在尝试使用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,
    });
  });

0 个答案:

没有答案