【发布时间】:2018-12-10 07:03:34
【问题描述】:
我有一个显示项目项的视图。项目信息位于 Projects(父)组件的数据对象中。
父组件:
import React from 'react';
import './projects.css';
import { Project } from '../projects/project/Project';
export class Projects extends React.Component {
constructor(props) {
super(props);
var projects = [
{
name: "Project 01",
desc: "A paragraph, from the Greek paragraphos, to write beside or written beside, is a self-contained unit of a discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences.",
img: "http://wenuka.com/img/back.jpg"
},
{
name: "Project 02",
desc: "A paragraph, from the Greek paragraphos, to write beside or written beside, is a self-contained unit of a discourse in writing dealing with a particular point or idea.",
img: "http://wenuka.com/img/back.jpg"
},
{
name: "Project 03",
desc: "A paragraph, from the Greek paragraphos, to write beside or written beside, is a self-contained unit of a discourse in writing one or more sentences.",
img: "http://wenuka.com/img/back.jpg"
}
]
}
render() {
return (
<section className="projects bg-ash">
<Project/>
</section>
);
}
};
项目项的 HTML 代码位于项目(子)组件中,如下所示。
子组件:
import React from 'react';
import './project.css';
export class Project extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className="container work-item">
<div className="row">
<div className="col-lg-5">
<img src="http://wingman.mediumra.re/assets/img/graphic-product-paydar.jpg"/>
</div>
<div className="col-lg-5 image-box">
<h5>Project Name</h5>
<p>To write beside or written beside, is a self-contained unit of a discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences.</p>
</div>
</div>
</div>
);
}
};
我需要使用子组件将每个元素显示为数据对象中的一个项目。
【问题讨论】:
-
在
Project组件上,将对象作为道具传递并尝试
标签: javascript reactjs components react-props react-state-management