【发布时间】:2019-08-10 06:43:21
【问题描述】:
所以我正在构建一个简单的 React 应用程序。这是我第一次使用它。所以我构建了这个组件:
import React, { Component } from "react";
import { Link } from "react-router-dom";
class FeatureBlock extends Component {
constructor(props) {
super(props);
}
render() {
//code here
return (
<li className="work-list-item" id={this.props.id}>
<Link to={this.props.src}>
<div className="thumbnail-wrapper">
<img width={this.props.width} height={this.props.height} src={this.props.src} alt={this.props.alt} />
</div>
<div className="work-info">
<div className="work-content">
<h2>{this.props.title}</h2>
<div className="excerpt">{this.props.contentClass}</div>
</div>
</div>
</Link>
</li>
);
}
}
export default FeatureBlock;
我将它导入到我的 index.js 文件中,如下所示:
import React, { Component } from "react";
import test from "./test";
import { Link } from "react-router-dom";
import FeatureBlock from "../FeatureBlocks/FeatureBlock";
class testing extends Component {
render() {
return (
<div>
<div className="component-container jobs-listing-component contact-page-component full-width-bg">
<test id="test-id" title="Test Title" titleDesc="" contentClass="">
<div className="work-archive-component">
<ul className="work-list">
<FeatureBlock title="Test Website" id="test-id">
</FeatureBlock>
</ul>
</div>
</test>
</div>
</div>
);
}
}
export default testing;
这在我的脑海中似乎是正确的逻辑,但它不起作用。就像我说的那样,我很新,我只是想做一些简单的工作并在这里连接点。任何和所有的帮助都会很棒!只求学习经验。谢谢!
顺便说一句 我的文件夹结构是这样的:
src
--testing
----index.js
----test.js
--FeatureBlocks
----FeatureBlock.js
错误列表:
【问题讨论】:
-
这里的“不工作”是什么意思?你遇到了什么错误?
-
您希望
this.props包含宽度高度等,但是您不会将这些道具传递给<FeatureBlock ... /> -
因为你刚刚进入 React,所以看看 Hooks 而不是 Classes
标签: javascript reactjs components