张延森 5 years ago
parent
commit
919cad8fc6
1 changed files with 14 additions and 12 deletions
  1. 14
    12
      src/components/uploadImage/ImageUpload.jsx

+ 14
- 12
src/components/uploadImage/ImageUpload.jsx View File

@@ -12,20 +12,22 @@ class ImageUpload extends React.Component {
12 12
     fileList: [],
13 13
   };
14 14
 
15
-  handleChange = info => {
16
-    this.setState({ fileList: info.fileList })
17
-    if (info.file.status === "uploading") {
18
-      this.setState({ loading: true });
19
-      return;
20
-    }
21
-  };
15
+  handleChange = ({ file, fileList }) => {
16
+    const { status, response } = file
17
+    this.setState({ fileList, loading: status === "uploading" })
22 18
 
23
-  handleUploadSucess = (url) => {
24
-    console.log(url,"33-------")
25 19
     if (typeof this.props.onChange === 'function') {
26
-      this.props.onChange(url);
20
+      const image = status === 'done' ? response : undefined
21
+      this.props.onChange(image);
27 22
     }
28
-  }
23
+  };
24
+
25
+  // handleUploadSucess = (url) => {
26
+  //   console.log(url,"33-------")
27
+  //   if (typeof this.props.onChange === 'function') {
28
+  //     this.props.onChange(url);
29
+  //   }
30
+  // }
29 31
 
30 32
   render() {
31 33
     const uploadButton = (
@@ -41,7 +43,7 @@ class ImageUpload extends React.Component {
41 43
         className="avatar-uploader"
42 44
         onChange={this.handleChange}
43 45
         fileList={this.state.fileList}
44
-        onSuccess={this.handleUploadSucess}
46
+        // onSuccess={this.handleUploadSucess}
45 47
       >
46 48
         {this.state.fileList.length >= 1 ? null : uploadButton}  
47 49
       </Upload>