react,antd-mobile图片组件并带有预览功能

本文介绍了如何在React项目中利用antd-mobile库创建一个具有预览功能的图片组件。通过引用antd-mobile的ImagePicker和Preview组件,详细讲解了组件的配置和使用方法,帮助开发者实现移动端图片上传和预览的交互体验。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

import React, { Component } from 'react';
import { Image, Space, ImageViewer } from 'antd-mobile';
import { Skeleton } from 'antd';

const fileDocDownloadPath = 'api/docrepo/download?attachmentId=';
class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
   srcList: [
        'https://images.unsplash.com/photo-1620476214170-1d8080f65cdb?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3150&q=80',
        'https://images.unsplash.com/photo-1601128533718-374ffcca299b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3128&q=80',
        'https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3113&q=80',
        'https://images.unsplash.com/photo-1624993590528-4ee743c9896e?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=200&h=1000&q=80',
      ], // 图片数据
      loadFlag: true,// 加载中
    };
  }



  handleClick = index => {
    const { srcList } = this.state;
    ImageViewer.Multi.show({ images: srcList,defaultIndex:index });
  };


  render() {
    const { srcList, loadFlag} = this.state;
    return (
      <div>
        {loadFlag ? (
            // 骨架屏
          <Skeleton.Image />
        ) : (
          <>
            <Space wrap>
              {srcList &&
                srcList.length > 0 &&
                srcList.map((el, index) => (
                  <Image
                    onClick={() => this.handleClick(index)}
                    src={el}
                    width="2rem"
                    fit="cover"
                    height="2rem"
                    style={{ borderRadius: 4 }}
                  />
                ))}
            </Space>
          </>
        )}
      </div>
    );
  }
}
export default Index;

antd-mobile文档地址

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值