【发布时间】:2020-07-27 09:22:32
【问题描述】:
我在 ReactJs 中传递图像道具时遇到问题
这是我的代码:component/Table/index。该组件用于 2 个表(订单和产品),所以我创建喜欢这个
import React from 'react';
import {Table, Image} from 'react-bootstrap';
import '../Table/index.css';
import Button from '../Button/index';
const TableItem = ({datas, columns}) => {
return(
<Table striped bordered hover>
<thead>
<tr>
{columns.map(name => <th>{name}</th>)}
</tr>
</thead>
<tbody>
<tr>
{datas.map(data =>
<td>{data}</td>
)}
</tr>
</tbody>
</Table>
);
}
export default TableItem;
我必须像这样从app.js 导入该列的数据
<TableItem columns={["No.", "Image", "Name", "Category", "Price", "Action"]}
datas={["1", "https://place-hold.it/100x150", "MIlk tea", "Milk tea", "100000", "button"]}
/>
正如您在上面看到的,我已经导入了所有列的数据,但是有一个问题,在 Image 列中,我没有 <Image> 标记,因此无法为我显示图像链接的数据, 还有一栏是Action,在这一栏会有两个按钮,每个产品每一行的编辑和删除
如果我有很多数据,如何在app.js 文件中检索它
我不知道如何解决这个问题,谁能帮帮我,这对我来说太难了,因为我对 ReactJs 很陌生
【问题讨论】: