我想要做的就是抓住json数据将其作为元素呈现。这里是我有什么,但this.images
继续拿出空(和未定义/ null的,如果我没有在顶部设置如何让json数据反应呈现?
import React, { Component } from 'react';
import axios from 'axios';
export default class Grid extends Component {
constructor(props) {
super(props);
this.images = [];
}
componentWillMount() {
axios.get('grid-config.json')
.then((res) => {
this.setImageArray(res.data);
});
}
setImageArray(imageArray) {
let newArray = [];
for(let i = 0; i < imageArray.length; i++) {
newArray.push(imageArray[i]);
}
this.images = newArray;
}
render() {
const postData = this.props.images;
console.log(this.images);
return (
<div>
hello
</div>
);
}
}
您可以检查浏览器控制台,看看有没有错误吗? –
没有,我查了。在控制台中唯一的是[] - >这是for console.log(this.images) – Jamie