首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从获取数据api进行渲染(它显示在控制台日志中,但我不能在渲染中调用它)

如何从获取数据api进行渲染(它显示在控制台日志中,但我不能在渲染中调用它)
EN

Stack Overflow用户
提问于 2019-05-26 05:14:01
回答 1查看 65关注 0票数 1

我想从https://memegenerator.net获取API数据,它在控制台日志上显示数据,但我不知道如何调用它。

我在控制台日志中尝试了一些变量,但仍然没有显示任何内容

在这里获取代码

代码语言:javascript
复制
  fetch("http://version1.api.memegenerator.net//Comment_Create?entityName=Instance&entityID=72628355&parentCommentID=&text=first%20post%20best%20post&apiKey=demo")
  .then(response => response.json())
  .then((responseJson)=> {
    this.setState({
     dataSource: responseJson
    })
    console.log(responseJson(commentID));
  })
  .catch(error=>console.log(error)) 
  }`````


i need it to show data if i call {this.sate.commnedId}  to show commendId
 see console log in this image [1]: https://i.stack.imgur.com/aLorh.png
EN

回答 1

Stack Overflow用户

发布于 2019-05-26 17:55:33

代码语言:javascript
复制
 componentDidMount(){
       let dataSource = '';
      fetch("http://version1.api.memegenerator.net//Comment_Create?entityName=Instance&entityID=72628355&parentCommentID=&text=first%20post%20best%20post&apiKey=demo")
      .then(response => response.json())
      .then((responseJson)=> {
        this.setState({
         dataSource:responseJson.result.commentID
        })

       // console.log(responseJson.result.text); this show in console
        console.log(dataSource);
      })
      .catch(error=>console.log(error)) //to catch the errors if any
      }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56308752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档