应用程序.js:
import './App.css';
import HttpService from '../services/http-service'
import React, { Component } from 'react';
const http = new HttpService()
class App extends Component {
constructor(props){
super(props)
this.state = {accounts: ""}
this.loadData = this.loadData.bind(this)
}
loadData = () => {
http.getAccounts().then(res =>{
this.setState({accounts: res})
console.log(this.accounts)
return res
}, err => {console.log(err)})
}
render() {return (
<div className="container">
<h1 className="title">Retail API</h1>
<DisplayAcc accounts = {this.accounts} />
</div>
)}
}
export default App;
在 DisplayAcc 上,我的构造函数中有一个 console.log(this.props.accounts) 。输出未定义。我应该怎么办?我尝试添加这些行:
componentDidMount(){
this.loadData = this.loadData.bind(this)
}
仍然未定义。请指出错误,或者如果您有任何建议/最佳实践,我将非常感激,因为我对此很陌生。谢谢!
哆啦的时光机
红糖糍粑
千万里不及你
慕的地10843
相关分类