html - React 按钮与带有道具的图像
问题描述
现在学习反应,需要用不同的图像做一些类似的按钮。我的组件:
export default class Button extends Component {
render() {
return (
<button className="header_btn"></button>
)
}
}
如何使用道具将图像设置为此按钮?保存在本地存储中的图像
解决方案
嗨,请检查这个例子:这里我将 text 和 imageUrl 作为道具传递。
import React from "react";
export default class Button extends React.Component {
render() {
return (
<button className="header_btn">
<img height="15px" width="15px" src={this.props.imageUrl} />
{this.props.text}
</button>
)
}
}
您应该在 App.js 或任何其他组件中使用 Button 组件,如下所示:
<Button text="Click" imageUrl="https://www.tutorialspoint.com/latest/inter-process-communication.png" />
推荐阅读
- python - 如何忽略此参数的区分大小写?
- flutter - 如何处理单击 sliverlist 项目?
- eclipse - Eclipse Py-dev,深色主题在键入时删除文本突出显示?
- sendgrid - SendGrid 邮件始终处于待处理状态
- php - 如何自动为 Laravel Blade 模板中的所有链接添加一些查询参数?
- python - 如何复制绘图:Python 中的密度条形图
- linux - 如何找到除其中一个之外的 docker 容器 ID 列表?
- upload - Vaadin 14 上传图片,检索 tmp 名称
- json - JSON 将对象映射到 React 中的表
- reactjs - Quill(react markdown)编辑器在最初使用 props 值渲染时重新渲染。这正常吗?