@@ -5,9 +5,12 @@ export default {
5
5
render ( ) {
6
6
const uploaderProps = {
7
7
props : {
8
- action : '//jsonplaceholder.typicode.com/posts/ ' ,
8
+ action : 'https://www.mocky.io/v2/5cc8019d300000980a055e76 ' ,
9
9
multiple : false ,
10
- data : { a : 1 , b : 2 } ,
10
+ data : {
11
+ a : 1 ,
12
+ b : 2 ,
13
+ } ,
11
14
headers : {
12
15
Authorization : '$prefix $token' ,
13
16
} ,
@@ -25,24 +28,25 @@ export default {
25
28
// EXAMPLE: post form-data with 'axios'
26
29
const formData = new FormData ( ) ;
27
30
if ( data ) {
28
- Object . keys ( data ) . map ( key => {
29
- formData . append ( key , data [ key ] ) ;
30
- } ) ;
31
+ Object
32
+ . keys ( data )
33
+ . map ( key => {
34
+ formData . append ( key , data [ key ] ) ;
35
+ } ) ;
31
36
}
32
37
formData . append ( filename , file ) ;
33
38
34
- axios
35
- . post ( action , formData , {
36
- withCredentials,
37
- headers,
38
- onUploadProgress : ( { total, loaded } ) => {
39
- onProgress ( { percent : Math . round ( ( loaded / total ) * 100 ) . toFixed ( 2 ) } , file ) ;
40
- } ,
41
- } )
42
- . then ( ( { data : response } ) => {
43
- onSuccess ( response , file ) ;
44
- } )
45
- . catch ( onError ) ;
39
+ axios . post ( action , formData , {
40
+ withCredentials,
41
+ headers,
42
+ onUploadProgress : ( { total, loaded} ) => {
43
+ onProgress ( {
44
+ percent : Math . round ( ( loaded / total ) * 100 ) . toFixed ( 2 ) ,
45
+ } , file ) ;
46
+ } ,
47
+ } ) . then ( ( { data : response } ) => {
48
+ onSuccess ( response , file ) ;
49
+ } ) . catch ( onError ) ;
46
50
47
51
return {
48
52
abort ( ) {
@@ -61,17 +65,17 @@ export default {
61
65
error ( err ) {
62
66
console . log ( 'error' , err ) ;
63
67
} ,
64
- progress ( { percent } , file ) {
68
+ progress ( {
69
+ percent,
70
+ } , file ) {
65
71
console . log ( 'progress' , `${ percent } %` , file . name ) ;
66
72
} ,
67
73
} ,
68
74
} ;
69
75
return (
70
- < div
71
- style = { {
72
- margin : '100px' ,
73
- } }
74
- >
76
+ < div style = { {
77
+ margin : '100px' ,
78
+ } } >
75
79
< div >
76
80
< Upload { ...uploaderProps } >
77
81
< a > 开始上传</ a >
0 commit comments