File tree 2 files changed +14
-7
lines changed
2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ interface PlaceholderType {
96
96
| 属性 | 说明 | 类型 | 默认值 | 版本 |
97
97
| --- | --- | --- | --- | --- |
98
98
| item | 附件,同 Upload ` UploadFile ` | Attachment | - | - |
99
- | onRemove | 附件移除时的回调函数 | (item: Attachment) => void | - | - |
99
+ | onRemove | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除 | (item: Attachment) => boolean \| Promise | - | - |
100
100
101
101
## Semantic DOM
102
102
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ const {
26
26
getDropContainer,
27
27
placeholder,
28
28
onChange,
29
+ onRemove,
29
30
overflow,
30
31
imageProps,
31
32
disabled,
@@ -78,13 +79,19 @@ const mergedUploadProps = computed<UploadProps>(() => ({
78
79
onChange: triggerChange ,
79
80
}));
80
81
81
- const onItemRemove = (item : Attachment ) => {
82
- const newFileList = fileList .value .filter ((fileItem ) => fileItem .uid !== item .uid );
83
- triggerChange ({
84
- file: item ,
85
- fileList: newFileList ,
82
+ const onItemRemove = (item : Attachment ) =>
83
+ Promise .resolve (typeof onRemove === ' function' ? onRemove (item ) : onRemove ).then ((ret ) => {
84
+ // Prevent removing file
85
+ if (ret === false ) {
86
+ return ;
87
+ }
88
+
89
+ const newFileList = fileList .value .filter ((fileItem ) => fileItem .uid !== item .uid );
90
+ triggerChange ({
91
+ file: { ... item , status: ' removed' },
92
+ fileList: newFileList ,
93
+ });
86
94
});
87
- };
88
95
89
96
const getPlaceholderNode = (
90
97
type : ' inline' | ' drop' ,
You can’t perform that action at this time.
0 commit comments