ant-design Table框架中加入图片

 问题描述:想在 picture 列中,展示图片缩略图。

 我的代码:

  const [dataSource, setDataSource] = useState([
    {
      key: '0',
      picture: 'Quadratic_illustration.png',
      type: 'txt2img',
      model: 'sd',
    },
    {
      key: '1',
      picture: '../assets/portrait_photography.png',
      type: 'img2img',
      model: 'sd',
    },
  ]);

  const defaultColumns = [
    {
      title: 'Picture',
      dataIndex: 'picture',
      width: '30%',
      ...getColumnSearchProps('picture'),
      editable: true,
    },
    {
      title: 'Type',
      dataIndex: 'type',
      ...getColumnSearchProps('type'),
      editable: true,
    },
    {
      title: 'Model',
      dataIndex: 'model',
      ...getColumnSearchProps('model'),
      editable: true,
    },
    {
      title: 'Operation',
      dataIndex: 'operation',
      render: (_, record) =>
        dataSource.length >= 1 ? (
          <Popconfirm title="Sure to delete?" onConfirm={() => handleDelete(record.key)}>
            <a>Delete</a>
          </Popconfirm>
        ) : null,
    },
  ];

找到:在table显示图片_antd的Table组件如何插入图片-CSDN博客

还是没有反应。即使是console.log() 中的内容都没打印出来。

发现是受可搜索功能的影响。删除这行代码,可以打印出 record 的内容。

...getColumnSearchProps('picture')

 但是仍未正确显示图片。

最后发现将本地图片文件改为网页路径即可正确显示。

  const [dataSource, setDataSource] = useState([
    {
      key: '0',
      picture: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
      type: 'txt2img',
      model: 'sd',
    },
    {
      key: '1',
      picture: '../assets/portrait_photography.png',
      type: 'img2img',
      model: 'sd',
    },
  ]);

第一张照片可以显示,第二张照片不能。仍在寻找原因。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值