reactjs - 简单的 React 组件问题
问题描述
我在 html、css 和 JS HTML 下面有 hte:
<div id="app1"></div>
JS:
function hello(props){
return(
<div className="Person">
<h1>Name: {props.name}</h1>
<p>Age: {props.age}</p>
</div>
);
}
var app=(
<div>
<hello name="John" age="82"/>
<hello name="Jane" age="89"/>
</div>
);
ReactDOM.render(app,document.querySelector("#app1"));
CSS
.Person{
width:200px;
color:black;
box-shadow:0 2px 2px #ccc;
display:inline-block;
margin:10px;
padding:2px;
}
但是此代码仅在我们将组件名称作为任何其他名称时才有效,Person
导致以下错误
Uncaught ReferenceError: Person is not defined
at pen.js:-5
Uncaught ReferenceError: Person is not defined
at pen.js:-4
你可以假设Reactjs
并被ReactDOM
导入。
解决方案
尝试将第一个字母更改hello
为 capitol 之类Hello
的(仅该代码的错误似乎是一个缓存的东西可能没有编译,因为那里的 jsx 元素没有大写)你可以改为调用代码{hello('john', 82)}
作为替代
推荐阅读
- php - 如何减去类型不同的行的同一列?
- python - 在 Python 中未将值分配给 Protobuff 变量
- javascript - 如果 id 存在于 MySQL 中,则在模态上自动增加 id
- node.js - Mongoose insertMany().exec() 返回 TypeError
- mysql - mysql加入四个表并获取超过1个月的记录
- c++ - 如何在不中断的 switch case 语句中正确使用 C++ 中的 Fallthrough?
- javascript - 是否有 Javascript/HTML 表单基础网页/帖子?建了一个 Excel 表格,想把它放在网页上
- unity3d - 何时在 Unity3D 中使用 transform.position 和rigidbody.position
- php - 如何将phpmailer连接到联系表格
- java - OneSignal 通知处理程序调用“startActivity”