Commit 1b4d69b1 authored by baiyaaaaa's avatar baiyaaaaa Committed by 杨奕

change onError params

parent b14b0ef8
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
### 点击上传 ### 点击上传
::: demo 通过 slot 你可以传入自定义的上传按钮类型和文字提示。 ::: demo 通过 slot 你可以传入自定义的上传按钮类型和文字提示。
```html ```html
<el-upload <el-upload
...@@ -307,8 +308,9 @@ ...@@ -307,8 +308,9 @@
| on-preview | 可选参数, 点击已上传的文件链接时的钩子, 可以通过 file.response 拿到服务端返回数据 | function(file) | — | — | | on-preview | 可选参数, 点击已上传的文件链接时的钩子, 可以通过 file.response 拿到服务端返回数据 | function(file) | — | — |
| on-remove | 可选参数, 文件列表移除文件时的钩子 | function(file, fileList) | — | — | | on-remove | 可选参数, 文件列表移除文件时的钩子 | function(file, fileList) | — | — |
| on-success | 可选参数, 文件上传成功时的钩子 | function(response, file, fileList) | — | — | | on-success | 可选参数, 文件上传成功时的钩子 | function(response, file, fileList) | — | — |
| on-error | 可选参数, 文件上传失败时的钩子 | function(err, response, file) | — | — | | on-error | 可选参数, 文件上传失败时的钩子 | function(err, file, fileList) | — | — |
| on-progress | 可选参数, 文件上传时的钩子 | function(event, file, fileList) | — | — | | on-progress | 可选参数, 文件上传时的钩子 | function(event, file, fileList) | — | — |
| on-change | 可选参数, 文件状态改变时的钩子 | function(file, fileList) | — | — |
| before-upload | 可选参数, 上传文件之前的钩子,参数为上传的文件,若返回 false 或者 Promise 则停止上传。 | function(file) | — | — | | before-upload | 可选参数, 上传文件之前的钩子,参数为上传的文件,若返回 false 或者 Promise 则停止上传。 | function(file) | — | — |
| list-type | 文件列表的类型 | string | text/picture/picture-card | text | | list-type | 文件列表的类型 | string | text/picture/picture-card | text |
| auto-upload | 是否在选取文件后立即进行上传 | boolean | — | true | | auto-upload | 是否在选取文件后立即进行上传 | boolean | — | true |
......
function getError(action, option, xhr) { function getError(action, option, xhr) {
const msg = `fail to post ${action} ${xhr.status}'`; const msg = xhr.response
? (xhr.response.error || xhr.response)
: xhr.responseText
? xhr.responseText
: `fail to post ${action} ${xhr.status}'`;
const err = new Error(msg); const err = new Error(msg);
err.status = xhr.status; err.status = xhr.status;
err.method = 'post'; err.method = 'post';
...@@ -53,7 +58,7 @@ export default function upload(option) { ...@@ -53,7 +58,7 @@ export default function upload(option) {
xhr.onload = function onload() { xhr.onload = function onload() {
if (xhr.status < 200 || xhr.status >= 300) { if (xhr.status < 200 || xhr.status >= 300) {
return option.onError(getError(action, option, xhr), getBody(xhr)); return option.onError(getError(action, option, xhr));
} }
option.onSuccess(getBody(xhr)); option.onSuccess(getBody(xhr));
......
...@@ -143,9 +143,10 @@ export default { ...@@ -143,9 +143,10 @@ export default {
file.response = res; file.response = res;
this.onSuccess(res, file, this.uploadFiles); this.onSuccess(res, file, this.uploadFiles);
this.onChange(file, this.uploadFiles);
} }
}, },
handleError(err, response, rawFile) { handleError(err, rawFile) {
var file = this.getFile(rawFile); var file = this.getFile(rawFile);
var fileList = this.uploadFiles; var fileList = this.uploadFiles;
...@@ -153,7 +154,8 @@ export default { ...@@ -153,7 +154,8 @@ export default {
fileList.splice(fileList.indexOf(file), 1); fileList.splice(fileList.indexOf(file), 1);
this.onError(err, response, rawFile); this.onError(err, file, this.uploadFiles);
this.onChange(file, this.uploadFiles);
}, },
handleRemove(file) { handleRemove(file) {
var fileList = this.uploadFiles; var fileList = this.uploadFiles;
......
...@@ -106,8 +106,8 @@ export default { ...@@ -106,8 +106,8 @@ export default {
onSuccess: res => { onSuccess: res => {
this.onSuccess(res, rawFile); this.onSuccess(res, rawFile);
}, },
onError: (err, response) => { onError: err => {
this.onError(err, response, rawFile); this.onError(err, rawFile);
} }
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment