我习惯在class Example extends Component {
constructor (props) {
super(props)
this.state = { data: null }
}
componentDidMount() {
this.callApi()
}
callApi() {
ajax.api({
'/v1/get-data',
method: 'GET',
token: access_token
}, (error, response) => {
if (error == undefined) {
this.setState({ data: response.data })
}
})
}
render() {
if (this.state.data == null) return <LoaderSpinner />
return <ShowData data={this.state.data} />
}
}
中调用ajax api来获取初始数据以填充组件控件/列表。但是,建议的/标准的方式是什么?
{{1}}