constructor(props) {
super(props)
this.state = {
error: null,
isLoaded: false,
records: []
}
}
使用Jquery发送JSON请求
componentDidMount() {
$.getJSON('https://5c947470498269001487f032.mockapi.io/records').then(
response => this.setState({ records: response, isLoaded: true }),
error => this.setState({ isLoaded: true, error }))
}
使用axios发送JSON请求
componentDidMount() {
axios.get('https://5c947470498269001487f032.mockapi.io/records').then(response => this.setState({
records: response.data,
isLoaded: true
})).catch(error => this.setState({
error,
isLoaded: true
}))
}