diff --git a/components/upload/Preview.js b/components/upload/Preview.js index 1936b116f..b92cde3ec 100644 --- a/components/upload/Preview.js +++ b/components/upload/Preview.js @@ -11,7 +11,6 @@ export default class Preview extends Component { extraClass: '', style: {} } - this.imgRef = React.createRef() } static propTypes = { @@ -34,8 +33,8 @@ export default class Preview extends Component { imgOnLoad () { const radio = 0.6 - const imgWidth = this.imgRef.current.clientWidth - const imgHeight = this.imgRef.current.clientHeight + const imgWidth = this.imgRef.clientWidth + const imgHeight = this.imgRef.clientHeight const windowRadio = window.innerWidth / window.innerHeight const imgRadio = imgWidth / imgHeight if (isNaN(imgRadio)) { @@ -71,14 +70,16 @@ export default class Preview extends Component { return (
{ + this.imgRef = node + }} src={src} onLoad={this.imgOnLoad.bind(this)} /> diff --git a/components/upload/UploadAvatar.js b/components/upload/UploadAvatar.js index 7e284ffcb..59de6e8fe 100644 --- a/components/upload/UploadAvatar.js +++ b/components/upload/UploadAvatar.js @@ -36,9 +36,6 @@ class UploadAvatar extends Upload { ) this.onDraging = this.onDraging.bind(this) this.onDragEnd = this.onDragEnd.bind(this) - this.cropperRef = React.createRef() - this.canvasRef = React.createRef() - this.uploadRef = React.createRef() } componentWillReceiveProps (nextProps) { @@ -125,7 +122,7 @@ class UploadAvatar extends Upload { resetParams () { window.removeEventListener('mousemove', this.onDraging) window.removeEventListener('mouseup', this.onDragEnd) - this.uploadRef.current.value = '' + this.uploadRef.value = '' this.scale = 1 this.img = null @@ -166,7 +163,7 @@ class UploadAvatar extends Upload { } = this.state const canvasOrigin = document.getElementById('canvas-origin') const originRect = canvasOrigin.getBoundingClientRect() - const cropperRect = this.cropperRef.current.getBoundingClientRect() + const cropperRect = this.cropperRef.getBoundingClientRect() const canvasPreview = document.getElementById('canvas-preview') canvasPreview.width = cropperWidth canvasPreview.height = cropperHeight @@ -201,7 +198,7 @@ class UploadAvatar extends Upload { } zoom(e) { // 缩放canvas - e.preventDefault() + // e.preventDefault() const wheelDelta = e.wheelDelta || e.deltaY/120 let scale = this.scale + wheelDelta @@ -220,7 +217,7 @@ class UploadAvatar extends Upload { cropperWidth, cropperHeight } = this.state - const canvasRect = this.canvasRef.current.getBoundingClientRect() + const canvasRect = this.canvasRef.getBoundingClientRect() const deltaHeight = (this.containerHeight-cropperHeight)/2 const deltaWidth = (this.containerWidth-cropperWidth)/2 let maxTop @@ -367,7 +364,9 @@ class UploadAvatar extends Upload {
  • diff --git a/components/upload/UploadPhoto.js b/components/upload/UploadPhoto.js index 85fa25002..32137f17a 100644 --- a/components/upload/UploadPhoto.js +++ b/components/upload/UploadPhoto.js @@ -16,7 +16,6 @@ class UploadPhoto extends Upload { }, this.state ) - this.uploadRef = React.createRef() } closeModal () { @@ -87,7 +86,9 @@ class UploadPhoto extends Upload {