【发布时间】:2017-12-26 23:40:04
【问题描述】:
我对反应非常陌生,在将数据从一种方法传递到另一种方法时遇到问题。 这是我的反应语法:
var url = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1"
class App extends React.Component{
info(val){
console.log(val)
}
request(){
axios.get(url)
.then(function (response) {
this.info(response)
console.log(response.data);
})
}
render() {
return(
<div>
<h1>axios</h1>
{this.request()}
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById("target"))
我的目标是将响应数据从request 方法传递给info 方法。但是,我收到错误消息说"TypeError: Cannot read property 'info' of undefined"
你能帮我找出我缺少的东西吗?
【问题讨论】:
-
绑定问题,检查重复问题
标签: javascript reactjs react-native axios