react.js中调用API渲染数组图片 [英] Rendering array pictures from calling API in react.js
问题描述
我有包含
的API "图片": ["http:\/\/storage\/web\/source\/images\/2016-10-28\/edac054f88fd16aee7bc144545fea4b2.jpg","http:\/\/storage\/web\/source\/images\/2016-10-28\/9aa3217f37f714678d758de6f7f5222d.jpg",http:\/\/storage\/web\/source\/images\/2016-10-28\/5164ed92c205dc73a37d77e43fe1a284.jpg"]
我必须在 Carousel 中渲染这些图片.问题是我不知道如何从数组中渲染这些图片,这意味着每张图片都应该分别在每个滑块中输出.
这是我的代码:
const API = 'http://...';导出默认类 Api 扩展 React.Component {构造函数(道具){超级(道具)this.state = {滑块图片:[],}}fetchProfile(id) {让 url = `${API}${name}`;获取(网址).then((res) => res.json() ).then((数据) => {this.setState({滑块图片:data.data.pictures,})}).catch((错误) => console.log(error) )}componentDidMount() {this.fetchProfile(this.state.name);}使成为() {返回 (<div><div><轮播数据={this.state}/>
)}}
导出默认类 Carousel extends React.Component {使成为() {让数据 = this.props.data;返回(<div><React_Boostrap_Carousel animation={true} className="carousel-fade"><div ><img style={{height:500,width:"100%"}} src={data.slider_pics}/>
<div style={{height:500,width:"100%",backgroundColor:"aqua"}}>456
<div style={{height:500,width:"100%",backgroundColor:"lightpink"}}>789
</React_Boostrap_Carousel>