VUpload
VUpload wraps Element Plus Upload and adds built-in validation, filename sanitization, cover-file handling, and download-oriented preview behavior.
Basic Usage
Initialize the component from existing file data, use cover-file with limit="1", and mock a Promise-based http-request handler.
image/*,less than 5MB
- press delete to remove
Picture Card Download
Render seeded images with list-type="picture-card" and turn preview clicks into downloads through preview="download".
Drag Upload
Enable drag-and-drop upload with custom drag text, accepted formats, and built-in size/type hints.
Behavior Notes
model-valueis an input prop used to initialize or externally reset the internal file list. The component does not emitupdate:modelValue; useon-changeif you need to sync external state.- When
before-uploadis not provided,VUploadvalidatesaccept,size, andmax-file-name-lengthfor you. Providing a custombefore-uploadreplaces that built-in validation. - Selected filenames are sanitized before upload by removing spaces and special characters from the base name while keeping the extension.
- After a file leaves the
readystate,on-changereceives a cloned normalized array shaped like{ name, url, fileName, fileUrl }. While a newly selected file is still inready, it receives the rawUploadFileslist. - When
cover-fileis enabled, files with the same sanitized name replace older entries. Iflimitis1, selecting a new file after the limit is reached replaces the current file. preview="download"turns preview clicks into downloads. Usedownload-methodto override the default browser download. Otherpreviewvalues currently have no built-in behavior in this wrapper.force-update-flie-listfollows the current implementation spelling and forcesmodel-valueto overwrite an already initialized internal file list.- When
http-requestis provided, it must return a Promise becauseVUploadchainsthen,catch, andfinallyon it.
Value Formats
model-valueaccepts an array, a single object, or a string.- String values are parsed as a JSON array first. If parsing fails, they are treated as a
|-separated list of file URLs and converted to{ fileName, fileUrl }. - When
auto-uploadistrue, existing records are normalized fromfileName/fileUrlto the internalname/urlfields used byUpload. - When
auto-uploadisfalseandmodel-valueis an array, the array is used directly as the internalUploadFileslist.
API
VUpload Attributes
| Name | Description | Type | Default |
|---|---|---|---|
| model-value | initial or external file data | array / string / object | [] |
| action | upload URL | string | '#' |
| headers | request headers | object | — |
| method | HTTP method | string | 'post' |
| data | extra request payload passed to Upload | object / function / Promise | {} |
| name | uploaded file field name | string | 'file' |
| multiple | allow selecting multiple files | boolean | false |
| drag | enable drag and drop mode | boolean | false |
| with-credentials | send cookies with the request | boolean | false |
| show-file-list | whether to show the upload list | boolean | true |
| accept | accepted file types | string | '' |
| auto-upload | start upload immediately after selection | boolean | true |
| list-type | file list display type | enum | 'text' |
| http-request | custom upload function that must return a Promise | function | — |
| disabled | disable upload interaction | boolean | false |
| limit | max number of files | number | — |
| before-upload | custom pre-upload hook; overrides built-in validation | function | — |
| before-remove | hook before removing a file | function | — |
| on-change | callback when the file list changes | function | — |
| on-success | callback after a file uploads successfully | function | — |
| on-progress | callback during upload progress | function | — |
| on-error | callback after upload failure | function | — |
| on-exceed | callback when selected files exceed limit | function | — |
| crossorigin | native crossorigin attribute for upload resources | enum | — |
| list-inline | display the file list inline | boolean | false |
| cover-file | replace existing entries with the same name; when limit is 1, exceeding the limit replaces the current file | boolean | false |
| hide-button | hide the button trigger after reaching limit | boolean | false |
| show-tip | show the built-in format and size tip | boolean | true |
| size | max file size in KB | number | 5120 |
| size-tip | custom size tip text | string | '' |
| format-tip | custom accepted format tip text | string | '' |
| format-err-tip | custom message shown when type validation fails | string | '' |
| preview | preview click mode; only download has built-in behavior in this wrapper | enum | '' |
| download-method | custom download handler used when preview="download" | function | — |
| max-file-name-length | max allowed file name length | number | — |
| drag-text | custom text shown in drag mode | string | '' |
| btn-attrs | extra props passed to the built-in button trigger | object | {} |
| btn-text | custom button text | string | '' |
| force-update-flie-list | force model-value to overwrite an initialized internal file list | boolean | false |
VUpload Events
| Name | Description | Type |
|---|---|---|
| uploadchange | emitted before upload starts and after the custom upload promise settles | function |
VUpload Slots
VUpload does not forward custom slots. The button trigger, drag area, and tip content are rendered internally from props.
press delete to remove
press delete to remove