1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import Upload from '../index';
import axios from 'axios';
export default {
render: function render() {
var h = arguments[0];
var uploaderProps = {
props: {
action: '//jsonplaceholder.typicode.com/posts/',
multiple: false,
data: { a: 1, b: 2 },
headers: {
Authorization: '$prefix $token'
},
customRequest: function customRequest(_ref) {
var action = _ref.action,
data = _ref.data,
file = _ref.file,
filename = _ref.filename,
headers = _ref.headers,
onError = _ref.onError,
onProgress = _ref.onProgress,
onSuccess = _ref.onSuccess,
withCredentials = _ref.withCredentials;
// EXAMPLE: post form-data with 'axios'
var formData = new FormData();
if (data) {
Object.keys(data).map(function (key) {
formData.append(key, data[key]);
});
}
formData.append(filename, file);
axios.post(action, formData, {
withCredentials: withCredentials,
headers: headers,
onUploadProgress: function onUploadProgress(_ref2) {
var total = _ref2.total,
loaded = _ref2.loaded;
onProgress({ percent: Math.round(loaded / total * 100).toFixed(2) }, file);
}
}).then(function (_ref3) {
var response = _ref3.data;
onSuccess(response, file);
})['catch'](onError);
return {
abort: function abort() {
console.log('upload progress is aborted.');
}
};
}
},
on: {
start: function start(file) {
console.log('start', file, file.name);
},
success: function success(file) {
console.log('success', file);
},
error: function error(err) {
console.log('error', err);
},
progress: function progress(_ref4, file) {
var percent = _ref4.percent;
console.log('progress', percent + '%', file.name);
}
}
};
return h(
'div',
{
style: {
margin: '100px'
}
},
[h('div', [h(
Upload,
uploaderProps,
[h('a', ['\u5F00\u59CB\u4E0A\u4F20'])]
)])]
);
}
};