change onError params

pull/2775/head
baiyaaaaa 2017-02-15 00:35:34 +08:00 committed by 杨奕
parent b14b0ef8ac
commit 1b4d69b1be
4 changed files with 16 additions and 7 deletions

View File

@ -105,6 +105,7 @@
### 点击上传
::: demo 通过 slot 你可以传入自定义的上传按钮类型和文字提示。
```html
<el-upload
@ -307,8 +308,9 @@
| on-preview | 可选参数, 点击已上传的文件链接时的钩子, 可以通过 file.response 拿到服务端返回数据 | function(file) | — | — |
| on-remove | 可选参数, 文件列表移除文件时的钩子 | function(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-change | 可选参数, 文件状态改变时的钩子 | function(file, fileList) | — | — |
| before-upload | 可选参数, 上传文件之前的钩子,参数为上传的文件,若返回 false 或者 Promise 则停止上传。 | function(file) | — | — |
| list-type | 文件列表的类型 | string | text/picture/picture-card | text |
| auto-upload | 是否在选取文件后立即进行上传 | boolean | — | true |

View File

@ -1,5 +1,10 @@
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);
err.status = xhr.status;
err.method = 'post';
@ -53,7 +58,7 @@ export default function upload(option) {
xhr.onload = function onload() {
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));

View File

@ -143,9 +143,10 @@ export default {
file.response = res;
this.onSuccess(res, file, this.uploadFiles);
this.onChange(file, this.uploadFiles);
}
},
handleError(err, response, rawFile) {
handleError(err, rawFile) {
var file = this.getFile(rawFile);
var fileList = this.uploadFiles;
@ -153,7 +154,8 @@ export default {
fileList.splice(fileList.indexOf(file), 1);
this.onError(err, response, rawFile);
this.onError(err, file, this.uploadFiles);
this.onChange(file, this.uploadFiles);
},
handleRemove(file) {
var fileList = this.uploadFiles;

View File

@ -106,8 +106,8 @@ export default {
onSuccess: res => {
this.onSuccess(res, rawFile);
},
onError: (err, response) => {
this.onError(err, response, rawFile);
onError: err => {
this.onError(err, rawFile);
}
});
},