Skip to content

Upload Component

Upload Component

Upload component allows users to upload files by clicking or dragging. It supports multiple display modes, automatic/manual upload, and rich customization features.

Basic Usage

Upload files by clicking the upload button, use the action attribute to set the upload address.

Show CodeArrow
CopyGitHub

List Type

Upload component supports two file list display modes: text list and picture list. Use the list-type attribute to configure.

Text List (list-type="text")

Picture List (list-type="picture")

Show CodeArrow
CopyGitHub

Drag Upload

Setting the drag attribute enables drag upload mode, allowing users to drag files to a specific area for upload.

Show CodeArrow
CopyGitHub

Manual Upload

Setting auto-upload to false disables automatic upload, requiring the submit method to be called to manually start upload.

Show CodeArrow
CopyGitHub

Upload Restrictions

You can use accept, max-size, and limit attributes to restrict file type, size, and quantity respectively.

File Type Restriction (accept)

File Size Restriction (max-size)

Quantity Restriction (limit)

Show CodeArrow
CopyGitHub

Custom Upload

Through the http-request attribute, you can customize upload behavior for more flexible upload implementation.

Custom Upload Implementation (http-request)

Custom Additional Data (data)

Show CodeArrow
CopyGitHub

Event Handling

Upload component provides rich events for handling various state changes during the upload process.

Event Log

No log records
Show CodeArrow
CopyGitHub

Slot Usage

Through multiple slots, you can customize different parts of the upload component, including trigger buttons, file lists, etc.

Default Slot (Trigger Button)

Drag Area Slot (drag)

File List Item Slot (file-item)

Show CodeArrow
CopyGitHub

Upload Component API

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
actionUpload URLstring
headersSet upload request headersobject
multipleWhether to support multiple file selectionbooleanfalse
dataAdditional parameters for uploadobject
nameUpload file field namestringfile
with-credentialsSupport sending cookie credentialsbooleanfalse
acceptAccepted upload file typesstring
max-sizeFile size limit in MBnumber
file-listUploaded file listUploadFile[][]
auto-uploadWhether to upload immediately after file selectionbooleantrue
list-typeFile list typestringtext / picturetext
dragWhether to enable drag uploadbooleanfalse
disabledWhether disabledbooleanfalse
show-file-listWhether to show uploaded file listbooleantrue
limitMaximum number of uploads allowednumber
before-uploadHook before uploading file(file: File) => boolean | Promise<any>
before-removeHook before removing file(file: UploadFile, fileList: UploadFile[]) => boolean
http-requestOverride default upload behavior(options: UploadRequestOptions) => Promise<any>

UploadFile Type

AttributeDescriptionTypeAccepted Values
uidFile unique identifiernumber | string
nameFile namestring
sizeFile sizenumber
typeFile typestring
statusFile statusstringready / uploading / success / fail
percentageUpload progressnumber0-100
urlFile URL addressstring
responseUpload response dataany
errorUpload error infoError
rawRaw file objectFile

Events

Event NameDescriptionParameters
successTriggered when file upload succeeds(file: UploadFile, response: any)
errorTriggered when file upload fails(file: UploadFile, error: Error)
progressTriggered when file upload progress changes(file: UploadFile, percent: number)
changeTriggered when file status changes(file: UploadFile | null, fileList: UploadFile[])
exceedTriggered when file count exceeds limit(files: File[], fileList: UploadFile[])
removeTriggered when file is removed(file: UploadFile, fileList: UploadFile[])
previewTriggered when clicking uploaded file link(file: UploadFile)

Methods

Method NameDescriptionParameters
clearFilesClear file list
abortCancel upload(file?: UploadFile) Optional, specify file. Cancels all uploads if not provided
submitManually upload file

Slots

Slot NameDescriptionScope Parameters
defaultUpload trigger area
tipTip description text
fileFile list item{ file: UploadFile }

Style Variables

Upload component uses the following style variables, which can be customized through SCSS variables:

Variable NameDescription
$theme-color-primaryTheme color
$text-color-defaultText color
$border-color-defaultBorder color
$bg-color-defaultBackground color
$font-size-defaultDefault font size

Released under the MIT License