react实现上传图片并支持剪裁

react实现上传图片并支持剪裁_第1张图片react实现上传图片并支持剪裁_第2张图片

第一步:

"antd-cropper-img": "^1.1.0",

 第二步:

import CropperImage from 'antd-cropper-img';
import React, { useState } from 'react';
import { Upload } from 'antd';
const App = () => {
  const [fileList, setFileList] = useState([
    {
      uid: '-1',
      name: 'image.png',
      status: 'done',
      url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
    },
  ]);
  const onChange = ({ fileList: newFileList }) => {
    setFileList(newFileList);
  };
  const onPreview = async (file) => {
    let src = file.url;
    if (!src) {
      src = await new Promise((resolve) => {
        const reader = new FileReader();
        reader.readAsDataURL(file.originFileObj);
        reader.onload = () => resolve(reader.result);
      });
    }
    const image = new Image();
    image.src = src;
    const imgWindow = window.open(src);
    imgWindow?.document.write(image.outerHTML);
  };
  return (
    
      
        {fileList.length < 5 && '+ Upload'}
      
    
  );
};
export default App;

你可能感兴趣的:(react.js,前端,javascript)