我正在尝试从 .json 文件中获取数据。页面上没有显示任何内容。也许有人知道为什么?谢谢!这是文件https://s3-us-west-2.amazonaws.com/digicode-interview/Q1.json上的链接
import React from 'react';
import createReactClass from 'create-react-class';
import ReactDOM from 'react-dom';
import axios from 'axios';
class Data extends React.Component {
constructor(props) {
super(props);
this.state = {
array: []
};
}
componentDidMount(){
axios
.get('https://crossorigin.me/https://s3-us-west-2.amazonaws.com/digicode-interview/Q1.json')
.then(({ data })=> {
this.setState({
array: data.recipes.Ingredients
});
})
.catch((err)=> {})
}
render() {
const child = this.state.array.map((element, index) => {
return <div key={index}>
<p>{ element.data.name }</p>
</div>
});
return <div><div>{ child }</div></div>;
}
}
export default Data;