我正在尝试Card
根据items
对象中的项目数呈现组件,但在第 6 行出现错误。
import React from "react";
export class Cards extends React.Component {
render() {
let elements = [];
elements = this.props.items.map(item => {
<Card titles = {item.title} imgsrc = {item.urlToImage}
discr = {item.description} urls = {item.url}
/>
})
return (
{elements}
);
}
}
这是Card
组件:
import React from 'react'
export default ({titles, imgsrc, urls, discr}) => {
return (
<div className="cards">
<div className="card">
<div className="cardHead">
<h4>{titles}</h4>
</div>
<div className="cardBody">
<img src={imgsrc} alt="pst-img" />
</div>
<div className="cardFooter">
<p>{discr}</p>
<a className="buttn" href={urls}>
<button>Read More</button>
</a>
</div>
</div>
</div>
)
}