2 回答
TA贡献1856条经验 获得超11个赞
html仅在构造函数之后加载。使用react ref尝试一下:
constructor(props) {
super(props);
this.state = {
insightsData: [],
loading: true,
}
}
componentDidMount(){
let self = this;
let url2 = '/api/Insights/GetAuthorArticles?authorName=Peter_Smith&numRecords=5';
let url1 = `/api/Insights/GetAuthorArticles?authorName=${document.getElementById('dataElement').getAttribute('data-name').replace(/ /g, "_")}&numRecords=5`;
this.setState({loading:true});
var Promise = require("es6-promise");
Promise.polyfill();
axios.get(url)
.then((response) => {
self.setState({
insightsData: response.data.InsightsResults.Records
}, this.setState({loading:false}));
console.log(response.data.InsightsResults.Records);
});
}
添加回答
举报