在写项目的时候需要用到图片裁剪功能,使用react-cropper
1.安装
yarn add react-cropper
2.组件中引入
import Cropper from ‘react-cropper’
3,使用
<div className="image-cropper">
<div className="wrapper">
<Cropper
style={
{
width: "100%", height: "200" }}
aspectRatio={
1}
guides={
true}
src={
this.props.file}
ref={
cropper => {
this.cropper = cropper}}
/>
</div>
<div>
<div className="btn-edit" onClick={
this.cropImage}>确定</div>