我想从https://memegenerator.net获取API数据,它会在控制台日志中显示数据,但我不知道如何调用它
我尝试在控制台日志中输入一些变量,但仍然不显示任何内容
在这里获取代码
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
答案 0 :(得分:0)
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
}