Skip to content

Attachments File Upload Component ๐Ÿ“ช๏ธ โ€‹

Introduction โ€‹

The Attachments component is a feature-rich attachment management component that supports file list display, upload, drag-and-drop interaction, scroll browsing, and more. It is suitable for scenarios that require handling multiple file uploads and displays (such as form attachments, file management interfaces). The component has a built-in file upload button, drag-and-drop prompt area, and provides flexible custom slots and style configuration.

Code Examples โ€‹

Basic Usage โ€‹

Basic file list display and upload functionality, supports automatic file card generation.

Scroll Mode โ€‹

scrollX
scrollY
wrap

Supports three layout modes: horizontal scroll (scrollX), vertical scroll (scrollY), and auto wrap (wrap). Default is horizontal scroll.

Custom File List โ€‹

Customize file list display content through slots (overrides default FilesCard component).

Drag and Drop Upload โ€‹

Set fullscreen drag upload:

Drag files here to upload

The drag property enables drag and drop upload functionality, supporting custom drag target areas and visual feedback.

The dragTarget property can be an id selector string, a Ref instance, or an HTMLElement DOM. If not set, the default drag area is the current list.

If you want to enable drag upload for the entire page, set drag to true and set drag-target to 'document.body'.

Custom Scroll Buttons โ€‹

Override default left and right scroll button styles and interactions.

Props โ€‹

NameTypeRequiredDefaultDescription
itemsFilesCardProps[]No[]File list data (includes basic file info such as name, type, status, etc.)
overflow'scrollX' | 'scrollY' | 'wrap'No'scrollX'Scroll layout mode (horizontal scroll/vertical scroll/wrap)
listStyleCSSPropertiesNo{}Custom style for the list container
uploadIconSizestringNo'64px'Upload button icon size
dragTargetstring | Ref<HTMLElement> | nullNonullDrag target element (supports selector string or DOM ref, defaults to the component itself)
hideUploadbooleanNofalseWhether to hide the default upload button
limitnumberNoundefinedFile quantity limit (hides upload button if exceeded)
beforeUpload(file: File) => booleanNoundefinedPre-upload validation function (return false to prevent upload)
httpRequest(options: { file: File }) => Promise<void>NoundefinedCustom upload request function (must return a Promise)

Slots โ€‹

Slot NameSlot ParameterDescription
#file-list{ items: FilesCardProps[] }Custom file list content (overrides default FilesCard display)
#prev-button{ show: boolean, onScrollLeft: () => void }Custom left scroll button (scrollX mode), show controls visibility
#next-button{ show: boolean, onScrollRight: () => void }Custom right scroll button (scrollX mode), show controls visibility
#empty-upload-Custom upload area when file list is empty (default shows plus upload button)
#no-empty-upload-Custom upload placeholder when file list is not empty (default shows plus upload button)
#drop-area-Custom overlay content during drag upload (default shows upload icon and text)

Events โ€‹

Event NameCallback ParameterDescription
uploadChange(file: File, fileList: FileListProps)Triggered when file selection changes (includes selected file and current file list)
uploadSuccess(response: any, file: File, fileList: FileListProps)Triggered when file upload succeeds (returns response, current file, and file list)
uploadError(error: any, file: File, fileList: FileListProps)Triggered when file upload fails (returns error, current file, and file list)
uploadDrop(files: File[], props: FileListProps)Triggered when files are dropped (includes dropped files array and component props)
deleteCard(item: FilesCardProps, index: number)Triggered when the file card delete button is clicked (returns deleted file info and index)

Support for el-upload Props โ€‹

The component internally uses the elementplus el-upload component, so it supports most of its upload properties, such as: httpRequest, beforeUpload, etc. For details, please refer to: element-plus/upload

Features โ€‹

  1. Multiple Layout Modes: Supports scrollX (horizontal scroll), scrollY (vertical scroll), and wrap (auto wrap) layouts to adapt to different screen spaces and file quantities.
  2. Drag-and-Drop Upload Interaction: Built-in drag target area (customizable via dragTarget), shows a semi-transparent overlay prompt during drag, supports folder filtering and file type validation.
  3. Highly Customizable: Fully customize file list display via the #file-list slot (e.g., replace with custom card component), supports custom scroll buttons and upload button styles.
  4. File Status Management: With the FilesCard component, supports visual states for uploading (progress bar), completed, failed, etc., and automatically syncs file list updates.