Skip to content

Commit a183f6c

Browse files
feat: add directUpdate option to skip upload preview
1 parent fc0223a commit a183f6c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/runtime/components/FileUpload.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export interface FileUploadProps<M extends boolean = false> {
7272
* @defaultValue true
7373
*/
7474
interactive?: boolean
75+
/**
76+
* Skip preview and directly emit update event.
77+
* @defaultValue false
78+
*/
79+
directUpdate?: boolean
7580
required?: boolean
7681
disabled?: boolean
7782
/**
@@ -144,6 +149,7 @@ const props = withDefaults(defineProps<FileUploadProps<M>>(), {
144149
dropzone: true,
145150
interactive: true,
146151
fileDelete: true,
152+
directUpdate: false,
147153
layout: 'grid',
148154
position: 'outside'
149155
})
@@ -213,6 +219,14 @@ function formatFileSize(bytes: number): string {
213219
}
214220
215221
function onUpdate(files: File[], reset = false) {
222+
// @ts-expect-error - 'target' does not exist in type 'EventInit'
223+
let event = new Event('change', { target: { value: files } })
224+
225+
if (props.directUpdate) {
226+
emits('change', event)
227+
return
228+
}
229+
216230
if (props.multiple) {
217231
if (reset) {
218232
modelValue.value = files as (M extends true ? File[] : File) | null
@@ -225,7 +239,7 @@ function onUpdate(files: File[], reset = false) {
225239
}
226240
227241
// @ts-expect-error - 'target' does not exist in type 'EventInit'
228-
const event = new Event('change', { target: { value: modelValue.value } })
242+
event = new Event('change', { target: { value: modelValue.value } })
229243
emits('change', event)
230244
emitFormChange()
231245
emitFormInput()

0 commit comments

Comments
 (0)