fix: update remove property of upload #259

pull/263/head
wangxueliang 2018-11-16 10:32:11 +08:00
parent 1dbb9c1490
commit ba26eff2c9
5 changed files with 7 additions and 5 deletions

View File

@ -124,7 +124,8 @@ export default {
})
},
handleRemove (file) {
Promise.resolve(this.$emit('remove', file)).then(ret => {
const { remove } = getOptionProps(this)
Promise.resolve(typeof remove === 'function' ? remove(file) : remove).then(ret => {
// Prevent removing file
if (ret === false) {
return

View File

@ -14,7 +14,7 @@ Upload files manually after `beforeUpload` returns `false`.
<a-upload
action="//jsonplaceholder.typicode.com/posts/"
:fileList="fileList"
@remove="handleRemove"
:remove="handleRemove"
:beforeUpload="beforeUpload"
>
<a-button>

View File

@ -20,13 +20,14 @@
| showUploadList | Whether to show default upload list, could be an object to specify `showPreviewIcon` and `showRemoveIcon` individually | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean } | true |
| supportServerRender | Need to be turned on while the server side is rendering. | boolean | false |
| withCredentials | ajax upload with cookie sent | boolean | false |
| remove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when return value is `false` or a Promise which resolve(false) or reject. | Function(file): `boolean | Promise` | - |
### events
| Events Name | Description | Arguments |
| --- | --- | --- |
| change | A callback function, can be executed when uploading state is changing. See [change](#change) | Function | - |
| preview | A callback function, will be executed when file link or preview icon is clicked. | Function(file) | - |
| remove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when return value is `false` or a Promise which resolve(false) or reject. | Function(file): `boolean | Promise` | - |
### change

View File

@ -20,13 +20,13 @@
| showUploadList | 是否展示 uploadList, 可设为一个对象,用于单独设定 showPreviewIcon 和 showRemoveIcon | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean } | true |
| supportServerRender | 服务端渲染时需要打开这个 | boolean | false |
| withCredentials | 上传请求时是否携带 cookie | boolean | false |
| remove   | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象Promise 对象 resolve(false) 或 reject 时不移除。               | Function(file): `boolean | Promise` | 无   |
### 事件
| 事件名称 | 说明 | 回调参数 |
| --- | --- | --- |
| change | 上传文件改变时的状态,详见 [change](#change) | Function | 无 |
| preview | 点击文件链接或预览图标时的回调 | Function(file) | 无 |
| remove   | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象Promise 对象 resolve(false) 或 reject 时不移除。               | Function(file): `boolean | Promise` | 无   |
### change

View File

@ -69,7 +69,7 @@ export const UploadProps = {
listType: PropsTypes.oneOf(['text', 'picture', 'picture-card']),
// className: PropsTypes.string,
// onPreview: PropsTypes.func,
// onRemove: PropsTypes.func,
remove: PropsTypes.func,
supportServerRender: PropsTypes.bool,
// style: PropsTypes.object,
disabled: PropsTypes.bool,