正如您从标题中看到的那样,在react中传递道具是不起作用的。我不明白为什么。
主要Ap组件
import './App.css';
import Licence from './Licence';
function App() {
return (
<>
<Licence>
test={"Test123"}
</Licence>
</>
);
}
export default App;
其他组件
import React from 'react';
const Licence = (props) => {
return (
<div>
<h1>name : {props.test}</h1>
</div>
)
}
export default Licence;
问题如果我启动脚本并呈现页面,则不会显示任何内容。我做错了什么?
许可证组件对我来说很好!
你所要做的就是改变你在应用程序上的设置方式。道具需要在标签上传递,如下所示:
import './App.css';
import Licence from './Licence';
function App() {
return (
<>
<Licence test={"Test123"} />
</>
);
}
export default App;
更新您的应用程序组件:
```
<Licence
test={"Test123"} />
```
像这样通过
<Licence test={"Test123"} />
和类似的访问
const Licence = (props) => {
return (
<div>
<h1>name : {props.test}</h1>
</div>
)
}
另一种方式
<Licence>
Test123
</Licence>
像这样的访问
const Licence = (props) => {
return (
<div>
<h1>name : {props.children}</h1>
</div>
)
}