在代码中用于调用组件中的AJAX API以获得初始数据的位置

时间:2018-10-29 11:26:47

标签: reactjs preact

我习惯在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}}

0 个答案:

没有答案