我是Reactjs的新手,我的问题是reactjs应用程序何时上线。直到我允许它加载脚本,它才会从wordpress加载图像。 请向我展示处理此问题的良好做法或方法,谢谢!
componentDidMount() {
Axios.get(wordpressUrl).then(results => {
this.setState({
posts: results.data
});
console.log(this.state.posts);
}).catch(error => console.log(error));
}
this.state.posts是一个数组,其中包含来自axios响应的结果
https://starocean.whatstreetapp.com/wp/wp-json/wp/v2/posts?_embed
return (
<div>
<span className='header'> Welcome to News Feed!<br /></span>
<div className="news_container">
{this.state.posts.map(post => {
return (
<div key={post.link} className="post-wrapper" onClick={() => this.newTab(post.link)}>
<div className="post">
<h2 className="post-title">
<a href={post.link} target="_blank"
dangerouslySetInnerHTML={{ __html: post.title.rendered }}
/>
</h2>
{post.featured_media ?
<a href={post.link}><img src={post._embedded['wp:featuredmedia'][0].media_details.sizes['large'].source_url} /></a>
: null}
{post.excerpt.rendered ?
<div className="excerpt" dangerouslySetInnerHTML={{ __html: post.excerpt.rendered }} />
: null}
</div>
</div>
);
})}
</div>
</div>
);
答案 0 :(得分:0)
如果您想从https页面提供脚本,也应该在https页面中提供脚本。