ReactJS - 图片未显示在 Material-Table 的自定义列中

ReactJS - Image is not shown in a custom column of Material-Table

我正在研究 material-table 以呈现带有图像的自定义列,就像 this example in the official docs. But there is a little problem. The example online image from githubusercontent.com 工作得很好但是如果我在上给出本地图像的路径我的机器坏了。

在我的机器上有图像

有在线图片

图像尺寸或文件扩展名等没有问题,因为我从 githunusercontent.com 下载了相同的图像,但在本地计算机上也无法正常工作。

编辑

刚刚我在控制台看到一条小错误消息说

Not allowed to load local resource 'file-path' What to do now?

要显示来自本地机器的图像,您可以通过以下方式进行:

App.js 文件:

import React from 'react';

import MaterialTable from 'material-table';

export default class App extends React.Component {
  render() {
    return (
      <MaterialTable
        title="Render Image Preview"
        columns={[
          { title: 'Avatar', field: 'imageUrl', render: rowData => <img src={require('./img.jpeg')} style={{ width: 40, borderRadius: '50%' }} /> },
          { title: 'Name', field: 'name' },
          { title: 'Surname', field: 'surname' },
          { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
          {
            title: 'Birth Place',
            field: 'birthCity',
            lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
          },
        ]}
        data={[
          { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63, imageUrl: 'https://avatars0.githubusercontent.com/u/7895451?s=460&v=4' },
          { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34, imageUrl: 'https://avatars0.githubusercontent.com/u/7895451?s=460&v=4' },
        ]}
      />
    )
  }
}

注意:我已经下载了图像并将其从您在此处提供的 URL 重命名为 img.jpeg 并将其保存在 [=11 所在的同一目录中=] 文件位于.